Boost logo

Boost :

Subject: Re: [boost] rvalue ref best practices?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-06-12 16:20:19

On 06/12/2012 07:51 PM, Simonson, Lucanus J wrote:

> I also find copy Ellison and RVO harder to reason about than reference semantics because it is more complex and less explicit in the code to figure out whether the optimizations will be applied.

RVO is mostly an ABI issue. It always gets applied in non-ambiguous
scenarios, it's not an optimization that depends on the mood of the

For any non-POD type, values are passed by pointer. Likewise, when such
types are returned by value, the function takes a pointer to storage
suitable for that type. It constructs the value to return at that
storage location.

First optimization: calling a function that takes an argument by value
with a temporary will directly pass the pointer to the temporary to that

Second optimization: when calling a function that returns a value that
is directly used to construct an object, the callee uses the storage for
the object itself to construct it instead of constructing it in a
temporary and copying it.

All compilers implement those optimizations (even plain old ones like

Now there is the NRVO optimization, which is slightly more tricky.

Boost list run by bdawes at, gregod at, cpdaniel at, john at