title: Sorting a std::map by value before output & destroy
body: <p>I'm aware that map is not prepared to be sorted. It's heavily optimized for fast and random key access and actually doesn't support <code>std::sort</code>.</p>
  
  <p>My current problem is that I've a full <code>map&lt;std::string,int&gt;</code> which I'm not going to use anymore. I just need to extract 10 pairs in <code>value(int)</code> order and destroy it.</p>
  
  <p>The best thing, if it was possible, would be to sort it in place and then iterate it 10 times, but that apparently is not a solution.</p>
  
  <p>I'm trying different solutions as going through a <code>multimap&lt;int,string&gt;</code> (to allow duplicate keys), but I'd like to know if there is a more elegant solution, using stl algorithms as much as posible.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm using a map because for the 99% of the time, I need it as a map: fast key lookups to increase values. Just need a good way of later extracting in value order when I don't need the map anymore.</p>
  
  <p>Current approach whould be:</p>
  
  <ul>
  <li><code>std::copy</code> the <code>map(std::string,int)</code> to a <code>vector(pair(std::string,int))</code></li>
  <li>sort the vector</li>
  <li>get the first 10 values</li>
  <li>destroy vector and map</li>
  </ul>