title: How can I move an element to the end of a vector?
body: <pre><code>int main(){
      std::vector&lt;int&gt; vec;
      vec.push_back(1);
      vec.push_back(2);
      vec.push_back(vec[0]);
      for (auto it = vec.begin(); it != vec.end(); it++) {
          std::cout &lt;&lt; *it &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>This outputs [1, 2, 1], which I understand because the vector is making a copy of vec[0] and pushing it back. However, I would like the output to be like [2, 1] and was curious if I can accomplish this without using push_back() and then having to use erase();</p>
  
  <p>The goal: I want to be able to move an element in the vector to the end while the vector adjusts itself accordingly, so if I move an element at the 5th position to the end, all the elements after the original 5th position would move up, so the new 5th position would have the element at the old 6th position and so forth.</p>