I'm just starting to use lambdas, due to a specific problem I'm trying to solve. So basically I need a lambda with a capture to simulate a function, that is required to store some internal state. To achieve this, I want to overload a function, which currently is defined as follows:
template<typename Return, typename... Args>
using GlobalBindFunction = Return(*)(Args...);
template<typename Return, typename... Args>
void registerBindFunction(GlobalBindFunction<Return, Args...> pFunction)
{
//...
}
Now if I happen to pass in a capturing lambda, I need to call a different overload, and here's where the problem comes in - if it wasn't required to have access to "Return" and "Args...", it would be sufficient to just do:
template<typename Lambda> // typename Return, typename... Args => required
void registerBindFunction(Lambda&& pFunction)
{
//...
}
std::string_view strIdentifier;
auto lambda =
[strIdentifier](CallState& state)
{
// ...
};
registerBindFunction(std::move(lambda));
Most of the code could actually just work with the lambda-object instead of a function-pointer, but I've got no idea how extract the return-value & argument-list this way. Is there any way to define a template-alias like in the function-ptr example?
template<typename Return, typename... Args>
using Lambda = Return(???)(Args...);
I havn't been able to find much out via googling and/or looking at the type of my lambda via intellisense, but does somebody with expertise on lambdas got any idea? Thanks!
↧