Olaf Krzikalla: ...
template<typename T> void foo(boost::function<T> func) { /*...*/ }
void bar() {}
void baz() { foo(boost::bind(&bar)); // error }
So how do I get the first line of baz to work? That is, is there a generic way to compute the boost::function type from the bind result?
There is not because the boost::function type is not unique. Hmm, indeed. However wouldn't it be possible for the bind (member) function pointer overloads to return a "_bind_t_ex" type derived from _bind_t containing a function_type typedef? In my particular use case I will use bind with function pointers only.
In general you can't deduce a boost::function<> from the result of bind, even if you only use functions. function<void()> f1 = bind( bar ); // OK function<void(string)> f2 = bind( bar ); // OK function<void(int,int)> f3 = bind( bar ); // still OK In fact, this ability to ignore arguments is the primary reason to use bind(bar), if you didn't need it, you could have used just bar.