title: vector<unique_ptr<A> > in constructor - error: call to implicitly-deleted copy constructor
body: <p>I am passing a vector of <code>std::unique_ptr</code> of objects <code>A</code> as a parameter to a constructor of objects <code>Obj</code>. This is working when I use the <code>std::move</code> syntax as is shown below. However, if I add another object to the constructor's parameter list (the <code>mpq_class i</code> in the below code) I get an <strong>error message</strong> that reads</p>
  
  <pre><code>error: call to implicitly-deleted copy constructor of 'std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt;'
  </code></pre>
  
  <p>on OS X and </p>
  
  <pre><code>error: use of deleted function ‘std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(const std::unique_ptr&lt;_Tp, _Dp&gt;&amp;) [with _Tp = Interface; _Dp = std::default_delete&lt;Interface&gt;]’
  </code></pre>
  
  <p>on a linux system. </p>
  
  <p>In the function <code>getVector()</code> the vector of <code>unique_ptr</code> is created, then passed to the <code>Obj</code> constructor and the objects are added to another vector and returned.</p>
  
  <p>My <strong>question</strong> is why the code tries to call a copy constructor if I use <code>std::move</code> for the unique_ptrs and how to get rid of it!</p>
  
  <p><strong>The code</strong> that produces the error is shown below.</p>
  
  <pre><code>// g++ -Wall -O3 -std=c++1y -lgmpxx -lgmp
  #include &lt;vector&gt;
  #include &lt;gmpxx.h&gt;
  #include &lt;gmp.h&gt;
  #include &lt;memory&gt;
  #include &lt;iostream&gt;
  
  class A {
  public:
      A( int y ) : x(y) {}
      int x;  
  };
  
  
  class Obj {
  public:
      Obj( mpq_class i, std::vector&lt;std::unique_ptr&lt;A&gt; &gt; v ) : number(i), cont( std::move(v) ) {}
  
      mpq_class number;
      std::vector&lt;std::unique_ptr&lt;A&gt; &gt; cont;
  };
  
  
  std::vector&lt;Obj&gt; getVector()
  {
      std::vector&lt;Obj&gt; result;
      int M = 3, N = 5;
  
      for( int mm = 0; mm &lt; M; mm++ )
      {
          mpq_class rational;
          std::vector&lt;std::unique_ptr&lt;A&gt; &gt; abstractObjectsForConstructor;
          for(int nn = 0; nn &lt; N; nn++ )
          {
              mpq_class r(mm,nn);
              rational = r;
              abstractObjectsForConstructor.push_back( std::make_unique&lt;A&gt;(nn) );
          }
  
          result.emplace_back( rational, std::move(abstractObjectsForConstructor) );
      }
  
      return result;
  }
  
  int main()
  {
      std::vector&lt;Obj&gt; vec = getVector();
  
      for( unsigned int ii = 0; ii &lt; vec.size(); ii++ )
      {
          for( unsigned int jj = 0; jj &lt; vec[ii].cont.size(); jj++ )
          {
              std::cout &lt;&lt; vec[ii].cont[jj]-&gt;x &lt;&lt; '\t' &lt;&lt; std::endl;
          }
      }
  
  
      return 0;
  }
  </code></pre>
  
  <p>The whole error message reads:</p>
  
  <pre><code>In file included from vector_unique.cpp:2:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:265:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:15:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:628:
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1645:31: error: 
        call to implicitly-deleted copy constructor of 'std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt;'
              ::new((void*)__p) _Up(_VSTD::forward&lt;_Args&gt;(__args)...);
                                ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1572:18: note: 
        in instantiation of function template specialization 'std::__1::allocator&lt;std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt; &gt;::construct&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt;,
        std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &amp;&gt;' requested here
              {__a.construct(__p, _VSTD::forward&lt;_Args&gt;(__args)...);}
                   ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1453:14: note: 
        in instantiation of function template specialization
        'std::__1::allocator_traits&lt;std::__1::allocator&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &gt;
        &gt;::__construct&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt;, std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt; &amp;&gt;' requested here
              {__construct(__has_construct&lt;allocator_type, pointer, _Args...&gt;(),
               ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:1005:25: note: 
        in instantiation of function template specialization
        'std::__1::allocator_traits&lt;std::__1::allocator&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &gt;
        &gt;::construct&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt;, std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt; &amp;&gt;' requested here
          __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this-&gt;__end_), *__first);
                          ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:1203:9: note: 
        in instantiation of function template specialization 'std::__1::vector&lt;std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt;, std::__1::allocator&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &gt;
        &gt;::__construct_at_end&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; *&gt;' requested here
          __construct_at_end(__x.__begin_, __x.__end_);
          ^
  vector_unique.cpp:15:8: note: in instantiation of member function 'std::__1::vector&lt;std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt;, std::__1::allocator&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &gt;
        &gt;::vector' requested here
          class Obj {
                ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1572:18: note: 
        (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
              {__a.construct(__p, _VSTD::forward&lt;_Args&gt;(__args)...);}
                   ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1535:17: note: 
        in instantiation of function template specialization 'std::__1::allocator_traits&lt;std::__1::allocator&lt;Obj&gt;
        &gt;::construct&lt;Obj, const Obj &amp;&gt;' requested here
                  construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
                  ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:874:21: note: 
        in instantiation of function template specialization 'std::__1::allocator_traits&lt;std::__1::allocator&lt;Obj&gt;
        &gt;::__construct_backward&lt;Obj *&gt;' requested here
      __alloc_traits::__construct_backward(this-&gt;__alloc(), this-&gt;__begin_, this-&gt;__end_, __v.__begin_);
                      ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:1621:5: note: 
        in instantiation of member function 'std::__1::vector&lt;Obj, std::__1::allocator&lt;Obj&gt;
        &gt;::__swap_out_circular_buffer' requested here
      __swap_out_circular_buffer(__v);
      ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:1639:9: note: 
        in instantiation of function template specialization 'std::__1::vector&lt;Obj, std::__1::allocator&lt;Obj&gt;
        &gt;::__emplace_back_slow_path&lt;__gmp_expr&lt;mpq_t, mpq_t&gt; &amp;, std::__1::vector&lt;std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt;, std::__1::allocator&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &gt; &gt; &gt;'
        requested here
          __emplace_back_slow_path(_VSTD::forward&lt;_Args&gt;(__args)...);
          ^
  vector_unique.cpp:40:11: note: in instantiation of function template specialization 'std::__1::vector&lt;Obj,
        std::__1::allocator&lt;Obj&gt; &gt;::emplace_back&lt;__gmp_expr&lt;mpq_t, mpq_t&gt; &amp;, std::__1::vector&lt;std::__1::unique_ptr&lt;A,
        std::__1::default_delete&lt;A&gt; &gt;, std::__1::allocator&lt;std::__1::unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt; &gt; &gt; &gt;'
        requested here
                          result.emplace_back( rational, std::move(abstractObjectsForConstructor) );
                                 ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2515:31: note: 
        copy constructor is implicitly deleted because 'unique_ptr&lt;A, std::__1::default_delete&lt;A&gt; &gt;' has a
        user-declared move constructor
      _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&amp;&amp; __u) _NOEXCEPT
                                ^
  1 error generated.
  </code></pre>