I'm writing a template function that takes a function object (for now, a lambda) as a parameter, with lambda datatype as a template parameter, and returns the same type the lambda returns. Like this:
template<typename TFunctor, typename TReturn>
TReturn MyFunc(TFunctor &Func, TReturn) //The second arg is just to keep the template spec happy
{
return Func();
}
And the consumption code goes like this:
int n = MyFunc([](){return 17;}, int());
I don't like the ugly way the return datatype is specified. Is there some built-in typedef in the compiler-generated lambda class that would give me its return type? So that MyFunc can go somehow like this:
template<typename TFunctor>
TFunctor::return_type MyFunc(TFunctor &Func)
{ //...
I want it to return the same type that lambda returns without explicitly spelling out that type.
EDIT: for now, all lambdas I'm concerned with are argumentless. Variable capture does the trick just as well.
TFunctor
really is, it might have an overloadedoperator()
, that means the return type can depend on what arguments you give it. (This is not true for non-generic lambdas, though) - leemes