Hello Dave, Stuart, Dave Slutzkin wrote on 28/07/2005 at 6:21 p.m.:
std::for_each(v.begin(), v.end(), boost::bind(&Handler::Test1, _1, a));
This creates a functor with one argument, _1, which calls Handler::Test1 with _1 as this and a as argument 1 of Test1. Right.
I think what you want is: std::for_each(v.begin(), v.end(), boost::bind(&Handler::Test2, _1, a, b)); To create a functor with one argument, _1, which calls Handler::Test2 with _1 as this, a as argument 1 of Test2 and b as argument 2 of Test2. Right, that's exactly what I needed. Thanks.
// This doesn't compile //std::for_each(v.begin(), v.end(), // boost::bind(&Handler::Test2, _1, _2, a, b));
This creates a functor with two arguments, _1 and _2, which calls Handler::Test2 with _1 as this, _2 as argument 1 of Test2, a as argument 2 of Test2 and b as argument 3 of Test2. But Test2 only has two arguments, and for_each only takes a functor with one argument. This is very confusing.... Let me paraphrase your explanation: I was trying to feed an extra argument to bind, which takes parameters in this fashion: boost::bind(function, this, arg1, arg2, arg3, etc)
Right? If yes, what's the exact meaning of _1, _2 placeholders? Also, how does that mash with functions vs methods? Best regards, Oleg.