title: vector erase multiple regions, 2 x erase vs single assign?
body: <p>I need to erase 2 ranges of elements from vector, the vector looks like this:</p>
  
  <pre><code>std::vector&lt;int&gt; vec {0, 1, 2, 3, 4, 5, 6, 7};
  </code></pre>
  
  <p>for example I need to keep only numbers 3 and 4. (in reality this could be big objects)</p>
  
  <p>There are 2 options:</p>
  
  <p>1) take target elements and drop the rest:</p>
  
  <pre><code>vec.assign(vec.begin() + 3, vec.begin() + 5);
  </code></pre>
  
  <p>2) explicitly remove ranges:</p>
  
  <pre><code>vec.erase(vec.begin() + 6, vec.end()); // first end (it's cheap)
  vec.erase(vec.begin(), vec.begin() + 3); // then beginning (reallocates elements)
  </code></pre>
  
  <p>Which one of these 2 options will perform faster?</p>
  
  <p>Or is there even better way?</p>