The liabilities of binding rvalues to ref
deadalnix
deadalnix at gmail.com
Sun May 5 09:21:36 PDT 2013
On Sunday, 5 May 2013 at 16:14:01 UTC, Dicebot wrote:
> 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.
>
No, you won't be able to reach any of this anyway. Move semantic
is already cleanly implemented in D, so the C++ mess is
irrelevant here.
>> - 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.
Having a singleton as a value type, and not marking the postblit
as @disable is asking for trouble in general, nothing specific to
the discussion here.
More information about the Digitalmars-d
mailing list