title: How to resize an std::vector without loosing the existing data?
body: <p>I was implementing an algorithm that needs me to remove and add the same elements from a vector each iteration of a loop.</p>
  
  <p>Example:</p>
  
  <p>iteration 1 : |1 2 3 4| (size 4)</p>
  
  <p>iteration 2 : |1 3| 2 4 (size 2 with the elements '2' and '4' still there in memory but not accounted for in the size of the vector)</p>
  
  <p>iteration 3 : |1 2 3| 4 (size 3 with the element '4' still there)</p>
  
  <p>Basically, I want to be able to change the value returned by the size() function without affecting the vector for performance reasons.</p>
  
  <p>I know I could use another variable outside of my vector to keep track of its size, but I wanted to know if it could be possible directly internally in the std::vector container.</p>
  
  <p>Thanks for any help.</p>