Adapting Map Iterators Using STL/Boost/Lambdas

Posted by John Dibling on Stack Overflow See other posts from Stack Overflow or by John Dibling
Published on 2010-04-26T21:09:53Z Indexed on 2010/04/26 21:13 UTC
Read the original article Hit count: 142

Filed under:

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:

  1. Standard STL function objects & techniques
  2. Boost.Bind
  3. C++0x Lambdas

I know I'm not eraseing the elements. Don't worry about that; I'm just simplifying the problem to solve.

© Stack Overflow or respective owner

Related posts about c++