
while(i!=c->points.end()){ Info *ec=cs.get(*i++); list.add(ec->key); //Previous two lines could be written: list.add(cs.get(*i++)->key); }
grab_keys2 would look like this:
void grab_keys2(const AllInfo &cs,const Info *c){ Points list; std::for_each(c->points.begin(),c->points.end(), boost::bind(&Points::add, boost::bind(&Info::key, boost::bind(&InfoContainer::get, &cs, _1))));
Thanks for the reply. I can almost match that up to the parts in the while loop, except mention of "list" is missing. Should it be: boost::bind(&Points::add, &list, boost::bind(&Info::key, boost::bind(&InfoContainer::get, &cs, _1))));
However, if Points is std::set<int>, then "add" should be "insert"
Sorry. Points is a class that can be thought of as a wrapper for std::set. I thought I could simplify the example by substituting, but of course I hadn't thought it through properly had I. BTW, I was hoping I'd be able to do something like this: std::for_each(c->points.begin(),c->points.end(), list.add(cs.get( _1 )->key) ); But after some experiments with boost::lambda I see why this isn't possible. I think if just one call to bind is possible then it is worth it, but when bind is required 2 or more times, falling back to a while loop or a functor seems better. Is anyone else using a similar guideline? Darren