I\'m not sure if it\'s possible, so that\'s what I want to find out.
I\'d like to create a function which accepts any kind of functor/callable object, but I want to
template < typename T >
void option( function< void(T) > )
{
cout << typeid( T ).name() << endl;
}
template < typename T >
void option( void (*func)(T) )
{
option( function< void(T) >( func ) );
}
template< typename F, typename A >
void wrapper( F &f, void ( F::*func )( A ) const )
{
option( function< void(A) >( bind( func, f, placeholders::_1 ) ) );
}
template< typename F, typename A >
void wrapper( F &f, void ( F::*func )( A ) )
{
option( function< void(A) >( bind( func, f, placeholders::_1 ) ) );
}
template < typename T >
void option( T t )
{
wrapper( t, &T::operator() );
}
void test( int )
{
}
struct Object
{
void operator ()( float )
{
}
};
int main( int, char *[] )
{
Object obj;
option( test );
option( [](double){} );
option( obj );
return 0;
}
Based on information found here c++0x: overloading on lambda arity, which I found through @dyps link
This isn't the best solution, since it requires overloads for const/non-const/volatile etc. It does get the job done in terms of the original problem I was trying to solve...