title: How is std::vector insert implemented? C++
body: <p>Recently I was rereading ISO C++ standard, and found very interesting note:</p>
  
  <blockquote>
    <p>Note that for <code>std::vector</code>, the only constraint on type <code>T</code> of <code>std::vector&lt;T&gt;</code> is that type <code>T</code> must have copy constructor. Actually, if the memory of vector is full while insertion, is allocate a new memory of <code>size = 2 * oldSize</code> (this is implementation dependent) and then copy old elements in it and insert that one element.</p>
  </blockquote>
  
  <p>But Wait??</p>
  
  <p>To allocate new memory of type the we need something like this, <code>ptr = new T[2*size];</code></p>
  
  <ol>
  <li>How this is done, because the type <code>T</code> may not have a default constructor?</li>
  <li>Then Assignment, after allocating the memory we must assign old values to new memory, right?</li>
  <li>To taking into consideration this 2 things, how does <code>std::vector</code> do this with "ONLY COPY CONSTRUCTOR?" What implementation and language idioms are used?</li>
  </ol>