Boost logo

Boost Users :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2006-02-14 19:27:49


On 2/15/06, Stuart Dootson <stuart.dootson_at_[hidden]> wrote:
> On 2/14/06, Meryl Silverburgh <silverburgh.meryl_at_[hidden]> wrote:
> > I have a int vector, and I would like to loop thru the vector and call
> > a function which takes an int (in this case, I want to print).
> >
> >
> > void A::aFunction() {
> >
> > vector<int> aVector;
> > aVector.push_back(1);
> > aVector.push_back(2);
> > aVector.push_back(3);
> > aVector.push_back(4);
> >
> > // want to loop thru the list and call A::print(int i)?
> > }
> >
> >
> > void A::print(int i) {
> >
> > }
> >
> > how can I do that using boost bind library?
> >
>
> Easiest way is
>
> A anA;
> std::for_each(aVector.begin(), aVector.end(),
> boost::bind(&A::print, &anA, _1));
>
> HTH
> Stuart Dootson
>

Use 'this' if you're doing the loop in A::aFunction...

Stuart


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