
Kobi Cohen-Arazi wrote:
std::vector<Foo> array; // say it is already populated std::vectorstd::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