Variable expansion: Use std::function internally
This change will end up in the public API for KF6, since with std::function, we can capture scope, which is not possible via a simple function pointer.