title: How to filter items from a std::map?
body: <p>I have roughly the following code. Could this be made nicer or more efficient? Perhaps using <code>std::remove_if</code>? Can you remove items from the map while traversing it? Can we avoid using the temporary map?</p>
  
  <pre><code>typedef std::map&lt;Action, What&gt; Actions;
  static Actions _actions;
  
  bool expired(const Actions::value_type &amp;action)
  {
    return &lt;something&gt;;
  }
  
  void bar(const Actions::value_type &amp;action)
  {
    // do some stuff
  }
  
  void foo()
  {
    // loop the actions finding expired items
    Actions actions;
    BOOST_FOREACH(Actions::value_type &amp;action, _actions)
    {
      if (expired(action))
        bar(action);
      else
        actions[action.first]=action.second;
      }
    }
    actions.swap(_actions);
  }
  </code></pre>