I have the following:
class Foo
{
public:
std::string const& Value() const { return /*Return some string*/; }
};
typedef std::list<Foo> FooList;
FooList foos; // Assume it has some valid entities inside
std::vector<int> ints;
FooList::const_iterator it, iend = foos.end();
for (it = foos.begin(); it != iend; ++it)
{
ints.push_back(boost::lexical_cast<int>(it->Value()));
}
How can I implement the for loop using std::for_each
and boost::phoenix
? I tried a few approaches but it gets really really ugly (I had a ton of nested bind()
statements). I basically just want to see how clean & readable boost phoenix can make this for loop, so I'm not writing so much boilerplate code to iterate containers that have 1-2 lines of specialized logic.
Sometimes, doing lambdas pre-C++11 just seems too unreadable and unmaintainable to be worth the trouble.