<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>

The SGI STL has an extension called
```
select1st
```
. Too bad it's not in standard STL!