title: Shifting values of a vector in C++
body: <p>Assuming the following basic vector:</p>
  
  <pre><code> std::vector&lt;int&gt; numbers;
   numbers.push_back(0);
   numbers.push_back(1);
   numbers.push_back(2);
   numbers.push_back(3);
  </code></pre>
  
  <p>What is an efficient way to insert 6 new numbers in between 0 and 1?</p>
  
  <p>Here is my approach right now, but I feel like it's not very efficient:</p>
  
  <pre><code> for (int new_number=0;new_number&lt;6;new_number++) {
       numbers.emplace(numbers.begin()+1+new_number,new_number);
   }
  </code></pre>
  
  <p>The reason I don't like this approach is that <strong>numbers 1-3 have to be moved 6 times</strong>. Is there a way to move these numbers just once instead of doing it 6 times? Then I can use this loop:</p>
  
  <pre><code> for (int new_number=0;new_number&lt;6;new_number++) {
       numbers[new_number+1]=new_number;
   }
  </code></pre>
  
  <p>Here is what I am trying to accomplish:</p>
  
  <p>Vector Before Shifting:</p>
  
  <pre><code>0 1 2 3
  </code></pre>
  
  <p>Vector After Shifting:</p>
  
  <pre><code>0 X X X X X X 1 2 3
  </code></pre>