15 May
2013
15 May
'13
3:52 p.m.
013/5/15 Peter Dimov
You've omitted the only interesting part.
template< typename Arg > struct Q {...}; struct B { virtual void run() = 0; }; template< typename Fn, typename Arg > struct D : public B { Fn fn; D( Fn fn_) : fn( fn_) {} void run() { Q< Arg > q; fn( q) } // argument construction omitted }; struct X { B * b; template< typename Fn > X( Fn fn) : b( 0) { typedef typename Magic< Fn >::arg1_type arg_type; b = new D< Fn, arg_type >( fn); } void run() { b->run(); } }; I want to construct a Q<> in D::run() and pass it to fn. Magic<> can be specialized for raw function pointers, function<> etc.