
26 Jan
2009
26 Jan
'09
5:40 p.m.
AMDG Olaf Krzikalla wrote:
The following snippet won't compile since the compiler can't deduce the template argument:
template<typename T> void foo(boost::function<T> func) { /*...*/ }
void bar() {}
void baz() { foo(boost::bind(&bar)); // error foo
(boost::bind(&bar)); // OK foo(boost::function (boost::bind(&bar))); // OK } 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. Consider: struct F { typedef void result_type; template<class T> void operator()(const T&) const; }; boost::bind(F(), _1); In Christ, Steven Watanabe