title: push_back vs emplace_back to a std::vector<std::string>
body: <p>A similar questions exist in <a href="https://stackoverflow.com/questions/32941695/examples-where-stdvectoremplace-back-is-slower-than-stdvectorpush-back">here</a> and <a href="https://stackoverflow.com/questions/4303513/push-back-vs-emplace-back">here</a> but I think we haven't got a clear answer then I remake the question.</p>
  <p>The C++11 standards has two ways to add a new element in the end of vector they are <code>std::vector::push_back</code> and <code>std::vector::emplace_back</code>.</p>
  <p>The difference between them is the <code>std::vector::emplace_back</code> construct the object in place and <code>std::vector::push_back</code> basically copy the object (or primitive type) or move it to the end of vector.</p>
  <p>Then <code>std::vector::push_back</code> looks the better option to add primitive types into a <code>std::vector</code>. For example:</p>
  <pre><code>std::vector&lt;int&gt; vVec;
  vVec.push_back(10);
  int iVar 30;
  vVec.push_back(iVar);
  </code></pre>
  <p>But it is not so clear to me when we talk about objects. Let's take a vector of std::string for example. If I want to add a literal string I shall use <code>std::vector::emplace_back</code> and when I want to copy or move a string object I shall use <code>std::vector::push_back</code>?</p>
  <p>To make more clear what I'm asking about, let's see a few scenarios:</p>
  <p>1st scenario:</p>
  <pre><code>std::vector&lt;string&gt; vVec;
  std::string sTest(&quot;1st scenario&quot;);
  vVec.push_back(sTest);  
  vVec.emplace_back(sTest); 
  </code></pre>
  <p>Push_back make a copy of <code>sTest</code> and associate to the new element in the end of <code>vVec</code> meanwhile <code>emplace_back</code> create the string object in the end of <code>vVec</code> and copy the content of <code>sTest</code> into it.
  Which one is more efficient in this case or doesn't matter?</p>
  <p>2nd scenario:</p>
  <pre><code>std::vector&lt;string&gt; vVec;
  std::string sTest1(&quot;2st scenario&quot;);
  std::string sTest2(&quot;2st scenario&quot;);
  vVec.push_back(move(sTest1));   
  vVec.emplace_back(move(sTest2)); 
  </code></pre>
  <p>Push_back is ready to move semantic, but what happens with <code>emplace_back</code>? Which one is more efficient in this case?</p>
  <p>3rd scenario:</p>
  <pre><code>std::vector&lt;string&gt; vVec;
  std::string sTest(&quot;3st scenario&quot;);
  vVec.push_back(sTest.substr(4,4));
  vVec.emplace_back(sTest.substr(4,4));
  </code></pre>
  <p>Because the std::string::substr returns another std::string we have the same situation as the 2nd scenario?</p>
  <p>Conclusion</p>
  <p>if <code>std::vector::emplace_back</code> is more efficient than <code>std::vector::push_back</code> only when literals is involved (in place construction), does it really justifiable to be used? If does, can you give me some examples?</p>
  <p>Important to note that <code>std::vector::emplace_back</code> was implemented in c++11 not in c++0x then I suppose it has a good reason to exists.</p>