title: How to retrieve all keys (or values) from a std::map and put them into a vector?
body: <p>This is one of the possible ways I come out:</p>
  <pre><code>struct RetrieveKey
  {
      template &lt;typename T&gt;
      typename T::first_type operator()(T keyValuePair) const
      {
          return keyValuePair.first;
      }
  };
  
  map&lt;int, int&gt; m;
  vector&lt;int&gt; keys;
  
  // Retrieve all keys
  transform(m.begin(), m.end(), back_inserter(keys), RetrieveKey());
  
  // Dump all keys
  copy(keys.begin(), keys.end(), ostream_iterator&lt;int&gt;(cout, &quot;\n&quot;));
  </code></pre>
  <p>Of course, we can also retrieve all values from the map by defining another functor <strong>RetrieveValues</strong>.</p>
  <p>Is there any other way to achieve this easily? (I'm always wondering why <code>std::map</code> does not include a member function for us to do so.)</p>