title: vc++ 2010/2012: std::vector of a struct containing unique_ptr compiler error
body: <p>The following code generates the compiler error below (after the code), but not if the vector contains unique_ptr's directly (see commented code lines). Any ideas why?</p>
  
  <p>The question is more concerned with the code block in the "#if 1" block, the "#else" block generates the error (after changing "#if 1" to "#if 0") that is similar, but is more expected.</p>
  
  <pre><code>// MoveSemantics.cpp : Defines the entry point for the console application.
  //
  
  #include "stdafx.h"
  #include &lt;memory&gt;
  #include &lt;vector&gt;
  
  typedef std::unique_ptr&lt;int&gt; upi;
  
  struct S
  {
      S() : p(new int(123)) {}
      S(S&amp;&amp; s) : p( std::move(s.p) ) {} // NB: the move constructor is supposed to be used? (but not)
      upi p;
  };
  
  #if 1
  void test()
  {
      //std::vector&lt;S&gt; vs; // Okay
      //std::vector&lt;upi&gt; vupi(10); // Okay
      std::vector&lt;S&gt; vs(10); // Error! why in the hell does the compiler want to generate a copy constructor here??
  }
  #else
  void test()
  {
      std::vector&lt;S&gt; vs;
  
      vs.push_back( S() );
      const S&amp; s = vs.front();
      //S&amp; s = vs.front(); // fine!
      S s1 = std::move(s); // Error, but expected
  }
  #endif
  int _tmain(int argc, _TCHAR* argv[])
  {
      return 0;
  }
  </code></pre>
  
  <p>Compiler Error:</p>
  
  <pre><code>1&gt; error C2248: 'std::unique_ptr&lt;_Ty&gt;::operator =' : cannot access private member declared in class 'std::unique_ptr&lt;_Ty&gt;'
  1&gt;          with
  1&gt;          [
  1&gt;              _Ty=int
  1&gt;          ]
  1&gt;          c:\program files\microsoft visual studio 11.0\vc\include\memory(1435) : see declaration of 'std::unique_ptr&lt;_Ty&gt;::operator ='
  1&gt;          with
  1&gt;          [
  1&gt;              _Ty=int
  1&gt;          ]
  1&gt;          This diagnostic occurred in the compiler generated function 'S &amp;S::operator =(const S &amp;)'
  </code></pre>