Copy subset of a std::map
<p>I am trying to copy a subset of a std::map structure to a new map structure in the most efficient way. I can only think to a plain vanilla solution like this:</p>

<pre><code>// Example program
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;map&gt;

int main()
{
  // build map
  std::map&lt;int, int&gt; mymap;
  size_t num_el = 10;


  for(size_t i = 0; i &lt; num_el; ++i)
  {
      mymap.insert(std::pair&lt;int,int&gt;(i,i));
  }

 // copy submap
 int start_index = 5;
 std::map&lt;int,int&gt; output_map;
 std::map&lt;int,int&gt;::const_iterator it;

  for(it = mymap.find(start_index); it != mymap.end(); ++it)
  {
       output_map.insert(*it);
  }


  //print result
  std::map&lt;int,int&gt;::const_iterator pit;
  for(pit = output_map.begin(); pit != output_map.end(); ++pit)
  {
     std::cout &lt;&lt; pit-&gt;second &lt;&lt; " , ";   
  }

  std::cout &lt;&lt; std::endl;
}
</code></pre>

<p>Is there a better way to do this? </p>