Boost logo

Boost Users :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-04-26 19:35:05


Kobi Cohen-Arazi wrote:

> std::vector<Foo> array; // say it is already populated
> std::vector<std::string> tr; // the transformed
> instead using my handcrafted for loop, I would like to transform the
> std::list<Foo>::iterator endIter=array.end ();
> for (std::list<Foo>::iterator iter=array.begin();
> iter!=endIter ;++iter)
> {
> noExtResults.push_back (iter.get().replace (0,5, ""));
> }
>
> I know it should be something like:
> std::transform (array.begin(), array.end (), std::back_inserter(tr),
> bind(&Foo::get, _1));
>
> So here I'm stuck. The bind function will know to extract the string
> using get. But how to I get that string and do something like:
> bind(&std::string::replace (???))

I'd use straight Boost.Bind, not Lambda. But the syntax is the same:

std::transform(array.begin(), array.end(), std::back_inserter(tr),
  bind(&std::string::replace, bind(&Foo::get, _1), 0, 5, ""));

Or you could use one of the special iterators from Boost.Iterator
instead of the nested bind.

Sebastian Redl


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