title: Confused by how the rvalue reference vector::push_back function increases effciency
body: <p>From the cppreference.com, I found a simple example about using the std::move:</p>
  
  <pre><code>std::string str = "Hello";
  std::vector&lt;std::string&gt; v;
  
  // uses the push_back(const T&amp;) overload, which means 
  // we'll incur the cost of copying str
  v.push_back(str);                                    // First push_back
  std::cout &lt;&lt; "After copy, str is \"" &lt;&lt; str &lt;&lt; "\"\n";
  
  // uses the rvalue reference push_back(T&amp;&amp;) overload, 
  // which means no strings will be copied; instead, the contents
  // of str will be moved into the vector.  This is less
  // expensive, but also means str might now be empty.
  v.push_back(std::move(str));                        // Second push_back
  </code></pre>
  
  <p>The comment says that string copy was avoided.</p>
  
  <p>The first push_back will call: <code>void push_back(const value_type&amp; _Val)</code></p>
  
  <p>The second push_back will call: <code>void push_back(value_type&amp;&amp; _Val)</code></p>
  
  <p>I checked the implementation code of the two functions:</p>
  
  <pre><code>void push_back(const value_type&amp; _Val)
      {   // insert element at end
      if (_Inside(_STD addressof(_Val)))
          {   // push back an element
          size_type _Idx = _STD addressof(_Val) - _Unfancy(this-&gt;_Myfirst());
          if (this-&gt;_Mylast() == this-&gt;_Myend())
              _Reserve(1);
          _Orphan_range(this-&gt;_Mylast(), this-&gt;_Mylast());
          this-&gt;_Getal().construct(_Unfancy(this-&gt;_Mylast()),
              this-&gt;_Myfirst()[_Idx]);
          ++this-&gt;_Mylast();
          }
      else
          {   // push back a non-element
          if (this-&gt;_Mylast() == this-&gt;_Myend())
              _Reserve(1);
          _Orphan_range(this-&gt;_Mylast(), this-&gt;_Mylast());
          this-&gt;_Getal().construct(_Unfancy(this-&gt;_Mylast()),
              _Val);
          ++this-&gt;_Mylast();
          }
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>void push_back(value_type&amp;&amp; _Val)
      {   // insert by moving into element at end
      if (_Inside(_STD addressof(_Val)))
          {   // push back an element
          size_type _Idx = _STD addressof(_Val) - _Unfancy(this-&gt;_Myfirst());
          if (this-&gt;_Mylast() == this-&gt;_Myend())
              _Reserve(1);
          _Orphan_range(this-&gt;_Mylast(), this-&gt;_Mylast());
          this-&gt;_Getal().construct(_Unfancy(this-&gt;_Mylast()),
              _STD forward&lt;value_type&gt;(this-&gt;_Myfirst()[_Idx]));
          ++this-&gt;_Mylast();
          }
      else
          {   // push back a non-element
          if (this-&gt;_Mylast() == this-&gt;_Myend())
              _Reserve(1);
          _Orphan_range(this-&gt;_Mylast(), this-&gt;_Mylast());
          this-&gt;_Getal().construct(_Unfancy(this-&gt;_Mylast()),
              _STD forward&lt;value_type&gt;(_Val));
          ++this-&gt;_Mylast();
          }
      }
  </code></pre>
  
  <p>So, according to my understanding, both first push_back (<code>v.push_back(str);</code>) and second push_back (<code>v.push_back(std::move(str));</code>) will trigger the vector to construct a <code>std::string</code> type variable and attach it to the vector.</p>
  
  <p>So, actually in both push_back calls, string was not copied. And, for both push_back, the expense are the same, because both calls basically do the same thing except the second push_back will make the <code>str</code> input to be empty.</p>
  
  <p>As for the efficiency, the only difference I can think of is that the second push_back will not call the delete []cstring; in the destructor of std::string which makes the second push_back call a little bit more efficient.</p>
  
  <p>Not sure if my understanding is correct. Thanks a lot!</p>