The liabilities of binding rvalues to ref

Dicebot m.strashun at gmail.com
Sun May 5 09:14:00 PDT 2013


Few additional points:

On Sunday, 5 May 2013 at 16:07:12 UTC, deadalnix wrote:
> I wish to add to the discussion that you want to pass by ref 
> for 2 reasons (and the intent is very different) :
>  - You intend to modify the value in some meaningful way for 
> the caller. In which case, binding to rvalue don't make any 
> sense.

You may want to modify rvalue temporary for implementing some 
sort of move semantics like in C++11.

>  - You want to avoid creating copies, when this isn't 
> necessary. In this case, this is a performance reason, and 
> binding to rvalue make sense.

Not necessarily performance reason on its own, copy construction 
of given object may have an undesired side effects. Or it may be 
even some singleton'ish object.


More information about the Digitalmars-d mailing list