On Wed, May 15, 2013 at 5:13 PM, Oliver Kowalke
at least what I can do is to overload the ctor:
template< typename Arg > X( void(*fn)( Arg &) ) {...}
template< typename Arg > X( boost::function< void( Arg &) > fn) {...}
ctor is called then:
X x1( g); // OK
A a; boost::function< void( Y< char > &) > f1=boost::bind( & A::operator(), a, _1); X x2( f1);
boost::function< void( Y< int > &) > f2=boost::bind( g, _1); X x3( f2);
For function pointer it's OK - but the code using function<> and bind() looks a little bit clumsy:
X x2(boost::bind( & A::operator(), a, _1)); // will not compile
The last one is equivalent to just X x2(a); You could try something like this: class X { public: template< typename R, typename A0 > X(R (*p)(A0)) {} template< typename R, typename A0, typename A1 > X(R (*p)(A0, A1)) {} ... template< typename R, typename C, typename A0 > X(R (C::*p)(A0)) {} template< typename R, typename C, typename A0, typename A1 > X(R (C::*p)(A0, A1)) {} ... template< typename T > X(T f) : X(&T::operator()) {} }; This will not work with templated or overloaded operator() (and for this reason will not work with bind). But I agree that you should avoid this design.