15 May
2013
15 May
'13
8:35 a.m.
I need some help to extract the type of a callable which is passed as argument to the ctor of X. struct X { template< typename Fn > X( Fn fn) { ... code which evaluates Fn and extracts the type of the first arg of Fn } }; void f( int) {...} struct A { void operator()( char) {...} void g( string) {... } }; The code should evaluate in the ctor to the arguments of the callables: A a; X x1( f); -> int X x2( a); -> char X x3( bind( & A::g, a, _1) ); -> string I could overload the ctor of X for function pointers: template< typename Arg > X( void(*fn)( Y< Arg > &) ) {...} but how to deal with the other two callable types? result_of and function_traits did not work for me. Oliver