Boost logo

Boost Users :

Subject: Re: [Boost-users] Compile error using boost's tr1::bind
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-06-04 10:10:43


Tron Thomas:
...

> int main()
> {
> Value sum;
> int values[] = { 1, 2, 3, 4, 5 };
> std::for_each(values, values + 5, std::tr1::bind(&Value::IncreaseBy,
> sum));
> std::cout << "The value is " << sum << std::endl;
> return 0;
> }

You need to use

    std::for_each(values, values + 5, std::tr1::bind(&Value::IncreaseBy,
&sum, _1));

&sum (or, if you prefer, std::tr1::ref(sum)) is needed so that bind doesn't
make a copy of sum. The _1 is needed to receive the number from values and
pass it to IncreaseBy as the 'amount'.


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