title: Why std::string append is not overloaded on rval ref?
body: <p>I'm familiar, that the <code>append</code> in <code>std::string</code> returns <code>std::string&amp;</code> and therefore it do not qualify to be moved from, so the result will not be moved.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;string&gt;
  
  
  int main()
  {
      std::string s = std::string(&quot;A&quot;).append(&quot;B&quot;);
      return s.size();
  }
  </code></pre>
  <p><a href="https://godbolt.org/z/M63aWW" rel="nofollow noreferrer">https://godbolt.org/z/M63aWW</a></p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;string&gt;
  
  
  int main()
  {
      std::string s = std::move(std::string(&quot;A&quot;).append(&quot;B&quot;));
      return s.size();
  }
  </code></pre>
  <p><a href="https://godbolt.org/z/jTnsac" rel="nofollow noreferrer">https://godbolt.org/z/jTnsac</a></p>
  <p>There you can see, that the latter example will produce one fewer allocation and therefore in this case it is better to move something that may looks like a temporary. My question is why they (the committee) do not add simple overload on <code>&amp;&amp;</code> to make the result of <code>append</code> either <code>std::string&amp;</code>, or <code>std::string&amp;&amp;</code> depending on the context? I mean something similar to <code>std::optional</code> is doing with <a href="https://en.cppreference.com/w/cpp/utility/optional/value" rel="nofollow noreferrer"><code>value</code></a>. Is there a example that will prove such optimization bogus?</p>