Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2003-05-30 07:25:30


Torbjörn Gyllebring <torbjorn.gyllebring_at_[hidden]> wrote:

> struct B
> {
> int f(int i){ cout << i << "\t";}
> int g(int i) const { cout << i << "\n";}
> };
>
> int main(int argc, char *argv[])
> {
> vector<int> ivec;
> for(int i = 0; i < 10; ++i)
> ivec.push_back( i);
> B b;
> for_each( ivec.begin(), ivec.end(), obj_fun( &b, &B::f));
> cout << endl;
> for_each( ivec.begin(), ivec.end(), obj_fun( &b, &B::g));
> system("PAUSE");
> return 0;
> }
>
> if something like this is already in boost (a friend who uses it claims
it's
> not) then im
> really sorry for wasting your time, else maybe this would be a candidate
for
> inclusion?

It is:

for_each(ivec.begin(), ivec.end(), boost::bind(&B::f, &b, _1));

Giovanni Bajo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk