Boost logo

Boost Users :

From: Oleg Smolsky (oleg.smolsky_at_[hidden])
Date: 2005-07-28 18:10:07


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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net