This is my trick:
template<typename F, typename TArg>
auto get_return_value(F * f = NULL, TArg * arg = NULL)
-> decltype((*f)(*arg));
Usage example:
template<typename F, typename T>
decltype(get_return_value<F,T>()) applyFtoT(F f, T t)
{
return f(t);
}
In the case where F is lambda:
int b = applyFtoT([](int a){return a*2}, 10);
The get_return_value function looks ugly, I think ... How to simplify it?
source
share