Adapting Map Iterators Using STL/Boost/Lambdas
- by John Dibling
Consider the following non-working code:
typedef map<int, unsigned> mymap;
mymap m;
for( int i = 1; i < 5; ++i )
m[i] = i;
// 'remove' all elements from map where .second < 3
remove(m.begin(), m.end(), bind2nd(less<int>(), 3));
I'm trying to remove elements from this map where .second < 3. This obviously isn't written correctly. How do I write this correctly using:
Standard STL function objects & techniques
Boost.Bind
C++0x Lambdas
I know I'm not eraseing the elements. Don't worry about that; I'm just simplifying the problem to solve.