Reputation: 47
How can I template these functions?
boost::function< void(int) > binder( void(*func)(int, char), int a1, char a2 )
{
return boost::bind( func, a1, a2 );
}
void proxy( boost::function< void(int) > func, int a1 )
{
boost::bind( func, a1 )();
}
I tried the following with no success:
template< typename R, typename A1, typename A2 >
static boost::function< void(int) > binder( R(*func)(A1,A2), A1 a1, A2 a2 )
{
return boost::bind( func, a1, a2 );
}
template< typename A1 >
static void proxy( boost::function< void(A1) > func, A1 a1 )
{
boost::bind( func, a1 )();
}
It would be nice if I could do without binder(). This is how I intend to use them:
void print( int i, char c );
boost::signals2::signal.connect(
boost::bind(
&proxy,
boost::bind(
&binder,
&print,
_1,
'a'
),
_1
)
);
I checked out the following with no luck:
how-to-use-manipulate-return-value-from-nested-boostbind
perform-argument-substitution-on-nested-boostbind-without-composition
can-i-use-boost-bind-with-a-function-template
Upvotes: 1
Views: 449
Reputation: 476950
You need to spell function pointers right:
R(*func)(A1, A2)
You will also need to specify the template parameters for forming a function pointer: Remember that binder
is not a function, but a template!
&binder<void, int, char>
&proxy<int>
Finally, you're not getting your signal variable right. Declare it like this:
boost::signals2::signal<void(int)> sig;
Then use:
sig.connect( /* all that stuff */ );
Upvotes: 2