I need to override connection between boost::signals2::signal
and boost::function
.
For this purpose I've created following template function:
template<typename T>
void bind(boost::signals2::signal<T> &signal, boost::function<T> function) {
// override code ...
}
I want to make use of this bind
as simple as it can be.
From what I've read in posts on similar issues, template parameter should be deduced from function arguments.
But in my case when there's no explicit parameter it's not working.
boost::signals2::signal<void ()> my_signal;
bind<void ()>(my_signal, boost::bind(&A::func, this)); // this works
bind(my_signal, boost::bind(&A::func, this)); // error: no matching function for call
Am I missing something?
Can there be any workaround to avoid explicit template parameter?
The second argument type is not std::function<T>
, but some bind type, so the compiler is unable to deduce the T
for the second function parameter. You need to tell the compiler "You are OK with not finding a type for T
in the second function parameter". This can be done by making the second parameter a non-deduced context.
template<typename T>
void bind(boost::signals2::signal<T> &signal,
typename std::common_type<boost::function<T>>::type function) {
// override code ...
}