
On 12/06/2012 06:34 AM, Chris Stankevitz wrote:
Hello,
Below I implement a function "Chain" that takes two functions and executes them both.
The first approach succeeds: direct function call.
The second approach succeeds: call via bind with explicit template arguments
The third and fourth approaches fail: call via bind without explicit template arguments (with/without boost::protect)
Question: Why do I have to use explicit template arguments when using bind with Chain? Chain is a template function. Its address isn't known until it gets instantiated. In order to bind a function, bind needs to know the address (aka which function to bind to). This means, that you have to specify the complete type.
Thank you,
Chris
===
#include<boost/bind.hpp> #include<boost/function.hpp>
template<typename TAFunc1, typename TAFunc2> void Chain(const TAFunc1& Func1, TAFunc2& Func2) { Func1(); Func2(); }
void f() { }
void foo() { boost::function<void()> x = boost::bind(f);
boost::function<void()> y = boost::bind(f);
Chain(x, y);
boost::bind(Chain<boost::function<void()>, boost::function<void()> >, x, y)();
boost::bind(Chain, x, y)();
boost::bind(Chain, boost::protect(x), boost::protect(y))(); } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users