Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(N)RVO is unrelated to the translation units. The term is commonly used to refer to two different copy elisions that can be applied one inside the function (from a local variable to the returned value) and by the caller (from the returned value to a local variable), and they should be discussed separately.</p> <p><strong>Proper RVO</strong></p> <p>This is performed strictly inside a function, consider:</p> <pre><code>T foo() { T local; // operate on local return local; } </code></pre> <p>Conceptually there are two objects, <code>local</code> and the returned object. The compiler can locally analyze the function and determine that the lifetime of both objects is bound: <code>local</code> only lives to serve as the source of a copy to the returned value. The compiler can then bind both variables in a single variable and use it.</p> <p><strong>Copy elision in the caller side</strong></p> <p>In the caller side, consider <code>T x = foo();</code>. Again there are two object, the returned object from <code>foo()</code> and <code>x</code>. And again the compiler can determine that the lifetimes are bound and place both objects on the same location.</p> <p>Further read: </p> <ul> <li><p><a href="http://definedbehavior.blogspot.com/2011/08/value-semantics-nrvo.html" rel="nofollow">Value semantics: NRVO</a></p></li> <li><p><a href="http://definedbehavior.blogspot.com/2011/08/value-semantics-copy-elision.html" rel="nofollow">Value semantics: Copy elision</a></p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload