title: Should std::string be returned by value from a function or by "std::string &s" as an argument?
body: <p>For returning a string out of a function, which of these two is more efficient (i.e. which one should I be using):</p>
  
  <pre><code>std::string f(const std::string&amp; s)
  {
      return s + "some text";
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>void f(const std::string&amp; s, std::string &amp;result)
  {
      result = s + "some text";
  }
  </code></pre>
  
  <p>I understand that maybe the answer depends on a particular compiler. But I want to know what the recommended approach (if there is one) is in a modern C++ code.</p>
  
  <p>Based on "Lightness Races in Orbit" comment below, here are some related questions that I found on stackoverflow <em>before</em> I asked this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/10231349/are-the-days-of-passing-const-stdstring-as-a-parameter-over">Are the days of passing const std::string &amp; as a parameter over?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10789740/passing-stdstring-by-value-or-reference">Passing std::string by Value or Reference</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18659043/pass-by-value-or-const-reference">Pass by value or const reference?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/17024519/stdstring-or-const-stdstring-argument-the-argument-is-internally-copi">&quot;std::string&quot; or &quot;const std::string&amp;&quot; argument? (the argument is internally copied and modified)</a></p>
  
  <p>None of which answer my particular question regarding returning a value from a function versus returning the string as an extra argument.</p>