title: Can I insert a vector to itself with std::vector::insert?
body: <p>Is it allowed by the C++03 standard to append a <code>std::vector</code> to itself? I wonder if the source iterators can become invalid if <code>v</code> needs to reallocate memory. In my STL implementation, the old memory is kept until the new memory has been created. But can I rely on this? If not, is <code>v.reserve(2 * v.size())</code> before the insert a good solution to avoid the reallocation altogether?</p>
  <pre><code>vector&lt;int&gt; v;
  v.reserve(3);
  v.push_back(1);
  v.push_back(2);
  v.push_back(3);
  // v may need to reallocate because its capacity may be less than 6.
  // Is this operation safe?
  v.insert(v.end(), v.cbegin(), v.cend());
  </code></pre>
  <p>or</p>
  <pre><code>// Here v will _not_ need to reallocate because it has enough capacity.
  // Is this operation safe?
  v.reserve(2 * v.size());
  v.insert(v.end(), v.cbegin(), v.cend());
  </code></pre>