title: return value optimization vs rvalue reference
body: <p>I learned about return value optimization (<a href="https://stackoverflow.com/questions/17159321/object-return-in-c">Object return in C++</a>, <a href="http://en.wikipedia.org/wiki/Return_value_optimization" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Return_value_optimization</a>, <a href="http://blog.knatten.org/2011/08/26/dont-be-afraid-of-returning-by-value-know-the-return-value-optimization/" rel="nofollow noreferrer">http://blog.knatten.org/2011/08/26/dont-be-afraid-of-returning-by-value-know-the-return-value-optimization/</a>) that prevents temporary object generation. </p>
  
  <p>I also learned about rvalue reference (<a href="http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html" rel="nofollow noreferrer">http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html</a>) that also can be used to prevent temporary object generation. </p>
  
  <p>Practically, can I just return value not worrying about performance degradation from copying objects?</p>
  
  <p>I mean, are those two code snippet equivalent?</p>
  
  <pre><code>A hello()
  {
      A a(20);
      cout &lt;&lt; &amp;a &lt;&lt; endl;
      return a;
  }
  
  // rvalue reference to prevent temporary object creation
  A&amp;&amp; a = hello();
  cout &lt;&lt; &amp;a &lt;&lt; endl;
  
  // expects compiler remove the temporary object
  A a = hello();
  cout &lt;&lt; &amp;a &lt;&lt; endl;
  </code></pre>