Boost logo

Boost :

From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2006-01-30 13:14:25

It is often the case that one is dealing with key value pairs when using the
STL containers. Sometimes, I have found the need to extract either the key
or the value from these pairs as part of a call to a standard C++ algorithm.
Unfortunatelly, unless one is using the SGI implementation of STL, function
objects such as select1st and select2nd are not available. So, I started to
look for a boost equivalent and finally found it in the bind library. Here
are the mechanisms, with the std prefix omitted for brevity:


MyMap mymap; // A map of some key type to some value type
MyVector myvector; // A vector of elements either of key type or value type,
depending on requirements

// Copy all keys from the map to the vector, which is assumed to containe 
elements of key type:
// Implementation using select1st, when available (e.g. SGI STL extensions)
// Implementation using boost::bind
// Copy all keys from the map to the vector, which, in this case, is assumed 
to containe elements of value type:
// Implementation using select2nd, when available
// Implementation using boost::bind
I hope this helps anyone else that needs similar functionality and doesn't 
want to reinvent the wheel.
Michael Goldshteyn

Boost list run by bdawes at, gregod at, cpdaniel at, john at