title: Moving elements from one vector to another using erase-remove paradigm
body: <p><a href="https://stackoverflow.com/questions/15004517/moving-elements-from-stdvector-to-another-one">This question</a> clearly articulates how to move contents from one <code>std::vector</code> to another. In short, there is a <code>std::move</code> call required to physically move the memory, while there is also a <code>std::erase</code> call necessary to resize the original vector to account for the removed elements.</p>
  
  <p>Is there a problem doing this using the <a href="https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom" rel="nofollow noreferrer">erase-remove paradigm</a> as one uses to delete from a vector while iterating over it (like <a href="https://stackoverflow.com/questions/8597240/how-to-delete-an-element-from-a-vector-while-looping-over-it">here</a>)?</p>
  
  <p>For example, something like this:</p>
  
  <pre><code>// Vector with values [0, 1, ..., 19]
  std::vector&lt;int&gt; myOldVec;
  for (int i = 0; i &lt; 20; i++) { myOldVec.push_back(i); }
  
  // New vector to move into
  std::vector&lt;int&gt; myNewVec;
  
  // Move from myOldVec to myNewVec if value is less than 5
  myOldVec.erase(
      std::remove_if(
          myOldVec.begin(),
          myOldVec.end(),
          [&amp;](const int x)
          {
              if (x &lt; 5)
              {
                  myNewVec.push_back(x);
                  return true;
              }
              return false;
          }
      ),
      myOldVec.end()
  );
  </code></pre>
  
  <p>The intended output would be</p>
  
  <pre><code>myOldVec --&gt; [5, 6, ..., 19]
  myNewVec --&gt; [0, 1, 2, 3, 4]
  </code></pre>
  
  <p>When I run this code it works in my tester. However, when dealing with objects instead of <code>int</code>s I worry that I'm not actually <em>moving</em> anything, but rather just referencing; for example, when doing the above with <code>std::vector&lt;MyObj&gt;</code> instead (with the appropriate lambda test).</p>
  
  <p>Is this really performing a move, or am I right to be concerned that I'm just sharing a reference?</p>