title: STL vector: Moving all elements of a vector
body: <p>I have two STL vectors <code>A</code> and <code>B</code> and I'd like to clear all elements of <code>A</code> and move all elements of <code>B</code> to <code>A</code> and then clear out <code>B</code>. Simply put, I want to do this:</p>
  
  <pre><code>std::vector&lt;MyClass&gt; A;
  std::vector&lt;MyClass&gt; B;
  ....
  A = B;
  B.clear();
  </code></pre>
  
  <p>Since <code>B</code> could be pretty long, it takes <code>k*O(N)</code> to do this operation, where <code>k</code> is a constant, and <code>N</code> is <code>max(size_of(A), size_of(B))</code>. I was wondering if there could be a more efficient way to do so. One thing that I could think of is to define <code>A</code> and <code>B</code> as pointers and then copy pointers in constant time and clear out <code>B</code>.</p>