title: Does the C++ standard specify STL implementation details for the compiler?
body: <p>While writing an answer to <a href="https://stackoverflow.com/questions/30909296/can-you-put-a-pimpl-class-inside-a-vector">this</a> question I faced an interesting situation - the question demonstrates the scenario where one would want to put a class in an STL container but fails to do so because of a missing copy constructor/move constructor/assignment operator. In this particular case the error is triggered by <code>std::vector::resize</code>. I made a quick snippet as a solution and saw another answer that had provided a move constructor instead of an assignment operator and copy constructor as I had. What was interresting that the other answer did not compile in VS 2012, while clang/gcc were happy with both approaches.</p>
  
  <p>First:</p>
  
  <pre><code>// Clang and gcc are happy with this one, VS 2012 is not
  #include &lt;memory&gt;
  #include &lt;vector&gt;
  
  class FooImpl {};
  
  class Foo
  {
      std::unique_ptr&lt;FooImpl&gt; myImpl;
  public:
      Foo( Foo&amp;&amp; f ) : myImpl( std::move( f.myImpl ) ) {}
      Foo(){}
      ~Foo(){}
  };
  
  int main() {
      std::vector&lt;Foo&gt; testVec;
      testVec.resize(10);
      return 0;
  }
  </code></pre>
  
  <p>Second:</p>
  
  <pre><code>// Clang/gcc/VS2012 are all happy with this
  #include &lt;memory&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  class FooImpl {};
  
  class Foo
  {
      unique_ptr&lt;FooImpl&gt; myImpl;
  public:
      Foo()
      {
      }
      ~Foo()
      {
      }
      Foo(const Foo&amp; foo)
      {
          // What to do with the pointer?
      }
      Foo&amp; operator= (const Foo&amp; foo)
      {
          if (this != &amp;foo)
          {
              // What to do with the pointer?
          }
          return *this;
      }
  };
  
  int main(int argc, char** argv)
  {
      vector&lt;Foo&gt; testVec;
      testVec.resize(10);
      return 0;
  }
  </code></pre>
  
  <p>To understand what was happening I looked at the STL sources in VS 2012 and saw that it really was invoking the move assignment operator so that is why my sample worked (I don't have a Linux machine accessible to understand what is going on in clang/gcc) and the other did not, since it had only the move copy constructor.</p>
  
  <p>So this created the following question - can the compiler freely decide how to implement STL methods (in this case <code>std::vector::resize</code>), since radically different implementations could cause non-portable code? Or is this simply a VS 2012 bug?</p>