Given a lambda, is it possible to figure out it\'s parameter type and return type? If yes, how?
Basically, I want lambda_traits
which can be used in fol
Though I'm not sure this is strictly standard conforming, ideone compiled the following code:
template< class > struct mem_type;
template< class C, class T > struct mem_type< T C::* > {
typedef T type;
};
template< class T > struct lambda_func_type {
typedef typename mem_type< decltype( &T::operator() ) >::type type;
};
int main() {
auto l = [](int i) { return long(i); };
typedef lambda_func_type< decltype(l) >::type T;
static_assert( std::is_same< T, long( int )const >::value, "" );
}
However, this provides only the function type, so the result and parameter
types have to be extracted from it.
If you can use boost::function_traits
, result_type
and arg1_type
will meet the purpose.
Since ideone seems not to provide boost in C++11 mode, I couldn't post
the actual code, sorry.