I have a helper method that takes as input a boost::function<>
type object and wraps the function with another functor that handles some other logistics.
Here is what my signature looks like:
class Example {
public:
typedef ... Callback;
...
template<typename T>
static Callback make_wrapper( const boost::function<void( T )>& );
};
If I try to pass make_wrapper the result of calling boost::bind
inline I get compilation errors about types being incompatible (Apple LLVM version 7.3.0)
class OtherClass {
public:
void method ( uint32_t );
};
OtherClass* other;
Example::Callback c = Example::make_wrapper ( boost::bind( &OtherClass::method, other, _1 ) );
this gives:
error: no matching function for call to 'make_wrapper'
note: candidate template ignored: could not match 'function' against 'bind_t'
I have found 2 ways around this:
Temp variable:
boost::function<void( uint32_t )> f = boost::bind( &OtherClass::method, other, _1 ); Example::Callback c = Example::make_wrapper ( f );
Call specific specialization of make_wrapper:
Example::Callback c = Example::make_wrapper<uint32_t> ( boost::bind( &OtherClass::method, other, _1 ) );
I would much prefer it if I could skip the extra hinting and call make_wrapper with the inline call to bind.
Is there a way that I can declare the signature of the make_wrapper template to help the compiler figure out the type without needing to use one of workarounds above?