inserting into stl containers using boosts' lambda

C

ckwood

Hi, I was wondering if there was a good way to insert a given member
varaible from a struct into a another container using the boost
framework:

struct SS {
int a,b;
};
vector<SS> v;
//...
set<int> s;
for_each(v.begin(), v.end(), bind( &set<unsigned>::insert, s, (_1 ->*
&SS::a) ));

Is there a better solution?

the easy/obvious soln is:
for(unsigned i =0; i < v.size(); i++) { s.insert(v.a); }


Thanks,
Cameron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top