title: Convert multimap<Key,Value> to vector<vector<Value>>
body: <p>I need to convert an <code>std::unordered_multimap&lt;Key,T&gt;</code> to an <code>std::vector&lt;std::vector&lt;T&gt;&gt;</code>. I need to do this because my program will need to sort all the data, and maps can't be sorted. An example:</p>
  
  <pre><code>// Map:
  { "A", 1 },
  { "A", 3 },
  { "A", 2 },
  { "B", 5 }, 
  { "B", 2 },
  
  // Map converted to vector&lt;vector&lt;Value&gt;&gt;:
  { 1, 3, 2 }, 
  { 5, 2 }
  </code></pre>
  
  <p>Right now I have this code which works. But I'm wondering if it's the best way to do it.</p>
  
  <pre><code>#include &lt;unordered_map&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;    
  
  int main()
  {
      typedef std::string Key_t;
      typedef int Value_t;
      typedef std::unordered_multimap&lt;Key_t, Value_t&gt; Map_t;
  
      const Map_t map = {
          { "A", 1 }, 
          { "A", 3 }, 
          { "A", 2 },
          { "B", 5 }, 
          { "B", 2 },
      };
  
      std::vector&lt; std::vector&lt; Value_t &gt; &gt; output;
  
      for ( Map_t::const_iterator it = map.cbegin(); it != map.cend(); )
      {
          std::vector&lt; Value_t &gt; temp;
          const Map_t::const_iterator end = map.upper_bound( it-&gt;first );
          for ( ; it != end; ++it )
              temp.push_back( it-&gt;second );
  
          output.push_back( temp );
      }
  
      // Print the result
      for ( const std::vector&lt; Value_t &gt;&amp; values : output )
      {
          for ( const Value_t&amp; value : values )
              std::cout &lt;&lt; value &lt;&lt; " ";
  
          std::cout &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1 3 2
  5 2
  </code></pre>
  
  <p>So, now I'm wondering if there's a faster/better way.</p>