title: How can I copy one map into another using std::copy?
body: <p>I would like to copy the content of one std::map into another. Can I use <code>std::copy</code> for that? Obviously, the following code won't work:</p>
  
  <pre><code>int main() {
    typedef std::map&lt;int,double&gt; Map;
    Map m1;
    m1[3] = 0.3;
    m1[5] = 0.5;
    Map m2;
    m2[1] = 0.1;
    std::copy(m1.begin(), m1.end(), m2.begin());
    return 0;
  }
  </code></pre>
  
  <p>This won't work because <code>copy</code> will call <code>operator*</code> on <code>m2.begin()</code> to "dereference" it and assign a value (all values are of type <code>std::pair&lt;const int, double&gt;</code>). Then it will call <code>operator++</code> to move to the next space in <code>m2</code>. Both of these operations don't work because of the <code>const</code> in <code>const int</code> and there is no space reserved for any new elements.</p>
  
  <p>Is there any way to make it work with <code>std::copy</code>? </p>
  
  <p>Thanks!</p>