The liabilities of binding rvalues to ref

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 6 07:26:31 PDT 2013


On 5/6/13 12:56 PM, Steven Schveighoffer wrote:
> On Sat, 04 May 2013 22:49:42 -0700, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> void fix(ref double x) { if (isnan(x)) x = 0; }
>
> ...
>
>> There may be other important patterns to address at the core, please
>> chime in. I consider (1) above easy to tackle, which leaves us with at
>> least (2). My opinion is that any proposal for binding rvalues to ref
>> must offer a compelling story about these patterns.
>
> But there are reasons to bind rvalues to references. I think deadalnix
> said it best, when you want to use ref to modify values, generally you
> want rvalues to be rejected (though I think rvalue is not a good
> description, consider that a pointer is an rvalue, but what it points to
> is an lvalue). When you want to use ref to avoid expensive copies, you
> want rvalues to be accepted.

Yah, so that's why I'm thinking "auto ref" would fit the bill there. 
Requiring pointers for lvalue binding and binding loosely to ref seems 
like the wrong move.

Andrei




More information about the Digitalmars-d mailing list