13/5/15 Andrey Semashev
On Wed, May 15, 2013 at 5:38 PM, Oliver Kowalke
wrote:
the class has to accept a callable object (function pointer or functor) - what is known is that it does return void and takes one argument. this is not a design decision, it is required by the user. as I showed in my example it can be solved - maybe a solution would be to overload the ctor with the type returned by boost::bind().
The bind function objects do not have a single operator(), and their operators() are templates.
OK - some simple code: struct B { virtual void run() = 0; }; template< typename Fn > struct D : public B { Fn fn; D( Fn fn_) : fn( fn_) {} void run() { fn(...) } // argument construction omitted }; struct X { B * b; template< typename Fn > X( Fn fn) : b( 0) { b = new D< Fn >( fn); } void run() { b->run(); } }; Constraints to Fn: returns void and has only one argument. I need to know in X::X() or D::run() what's the first and only argument of Fn. I believe the problem should be solvable - for function pointers it is easy, X() could be overloaded with function<>. The only remaining issue are objects created by bind() and passed to the ctor - I thought overloading X() with the type returned by bind() should work?!