title: C++ unique_ptr and map
body: <p>I'm trying to use the <a href="http://en.cppreference.com/w/cpp/memory/unique_ptr" rel="nofollow noreferrer">C++0x</a> <a href="http://msdn.microsoft.com/en-us/library/ee410601.aspx" rel="nofollow noreferrer"><code>unique_ptr</code> class</a> inside a <a href="http://en.cppreference.com/w/cpp/container/map" rel="nofollow noreferrer"><code>map</code></a> like so:</p>
  
  <pre><code>// compile with `g++ main.cpp -std=gnu++0x`
  
  #include &lt;string.h&gt;    
  #include &lt;map&gt;
  #include &lt;memory&gt;
  
  using namespace std;
  
  struct Foo {
      char *str;    
      Foo(char const *str_): str(strdup(str_)) {}
  };
  
  int main(void) {
      typedef std::map&lt;int, unique_ptr&lt;Foo&gt;&gt; Bar;
      Bar bar;
      auto a = bar.insert(Bar::value_type(1, new Foo("one")));
      return 0;
  }
  </code></pre>
  
  <p>However GCC gives me the following error (shortened, I think this is the relevant part, please test on your own C++ compiler):</p>
  
  <pre>
  main.cpp:19:   instantiated from here
  /usr/include/c++/4.4/bits/unique_ptr.h:214: error: deleted function ‘std::unique_ptr::unique_ptr(const std::unique_ptr&) [with _Tp = Foo, _Tp_Deleter = std::default_delete]’
  /usr/include/c++/4.4/bits/stl_pair.h:68: error: used here
  </pre>
  
  <p>I'm really not sure what I've done wrong, this works on MSVC. I have found very <a href="https://stackoverflow.com/questions/3763621/cx0-unique-ptr-gcc-4-4-4">similar</a> questions, that seem alike, however their solutions do not work for me.</p>
  
  <pre>
  matt@stanley:/media/data/src/c++0x-test$ gcc --version
  gcc-4.4.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3
  </pre>