title: Copy map of unique_ptr using map::insert
body: <p>Is there a possibility to deep-copy a <code>std::map</code> of <code>std::unique_ptr</code> to another one using <a href="http://en.cppreference.com/w/cpp/container/map/insert" rel="nofollow noreferrer"><code>std::map::insert</code></a> or <a href="http://en.cppreference.com/w/cpp/algorithm/copy" rel="nofollow noreferrer"><code>std::copy</code></a>?</p>
  
  <p>I have the following:</p>
  
  <pre><code>class MyObject {}
  
  std::map&lt;int32_t, std::unique_ptr&lt;MyObject&gt;&gt; entries1;
  
  // Populate entries1
  // ...
  
  std::map&lt;int32_t, std::unique_ptr&lt;MyObject&gt;&gt; entries2;
  
  entries2.insert(entries1.begin(), entries1.end());
  </code></pre>
  
  <p>Obviously, using a simple insert won't work, because <code>std::unique_ptr</code> is non-copyable:</p>
  
  <blockquote>
    <p>attempting to reference a deleted function</p>
  </blockquote>
  
  <p>In this answer <a href="https://stackoverflow.com/questions/2748295/how-can-i-copy-one-map-into-another-using-stdcopy/2748303#2748303">How can I copy one map into another using std::copy?</a>, a custom inserter is sugested together with <code>std::copy</code>, but I really don't know how to use it in my context.</p>
  
  <p>Is the manual implementation (iterating and copying each object in a loop) the only solution? E.g.:</p>
  
  <pre><code>for (const auto &amp;entry : entries1)
  {
      entries2.insert({ entry.first, std::make_unique&lt;MyObject&gt;(*entry.second) });
  }
  </code></pre>