Boost logo

Boost Users :

From: Darren Cook (darren_at_[hidden])
Date: 2003-08-25 06:05:05

I have a project with many occurences of while loops iterating through a
container, and operating on the data. I'd like to use for_each() and turn
them into one-liners, but I don't like writing one-off functor classes.

I was hoping boost::bind could help, but I've read the docs, scratched my
head, and failed to work out how the examples apply to my case. Maybe they
don't and I'm trying to use it for something it cannot do?

See an example below. My function currently looks something like grab_keys()
and I want it to look like grab_keys2().

Could some kind soul show me how to write this? (or explain why it cannot be




class Info{
int key;
std::set<int> points;

class InfoContainer{
Info* get(int);

void grab_keys(const InfoContainer &cs,const Info *c){
std::set<int> list;
std::set<int>::const_iterator i=c->points.begin();
        Info *ec=cs.get(*i++);
        //Previous two lines could be written: list.add(cs.get(*i++)->key);
//Do something with list here.

void grab_keys2(const AllInfo &cs,const Info *c){
Points list;
      boost::bind( /* what goes here? */ )
//Do something with list here.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at