title: C++ vector: should I copy or swap?
body: <p>I have a class  that has a vector member variable, which I fill up as follows:</p>
  
  <pre><code>class Foo {
  vector&lt;int&gt; v;
  void g() {
    vector&lt;int&gt; w;
    // fill w
    v = w;
  }
  
  };
  </code></pre>
  
  <p>My question: the temporary vector w can grow to be huge and I don't want to pay the price
  of copy construction. Should I be using std::swap instead of copy here? My understanding
  is that std::swap will be more efficient due to specialization for vector (where it
  will just swap pointers to the heap).  </p>