Boost logo

Boost Users :

From: Seb Martel (smartel_at_[hidden])
Date: 2005-09-22 13:01:25


> > In Pyhon:
> >
> > y = [foo(_1) for _1 in x]
> >
> > In C++:
> >
> > list<int> x;
> > x.push_back(...);
> > ..
> >
> > list<int> y;
> > for (list<int>::iterator it = x.begin(); x.end() != it; ++ it)
> > y.push_back( foo(y) );
> >
> > With boost, can we write the Python-like statement:
> >
> > copy( x.begin(), x.end(), magic_back_inserter(foo(_1), y) ); // pseudo-
> code
> >
>
>
> With the range_ex library in boost-sandbox, this would look like:
>
> boost::copy(
> x | boost::adaptor::transform(&foo)
> , std::back_inserter(y)
> );
>

What about:

        std::transform(
                x.begin(), x.end(), std::back_inserter(y),
                boost::bind( &foo, _1 ) );

Sebastien Martel


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