DIP 1016--ref T accepts r-values--Community Review Round 1

Daniel N no at public.email
Fri Jul 20 17:25:25 UTC 2018


On Friday, 20 July 2018 at 17:02:04 UTC, Jonathan M Davis wrote:
> On Friday, July 20, 2018 16:42:54 aliak via Digitalmars-d wrote:
>> On Friday, 20 July 2018 at 13:21:11 UTC, Jonathan M Davis
>>
>> But as for a UDA, maybe @implicit from the copy constructor 
>> DIP can be reused here?
>>
>> void f(@implicit ref A a) {}
>
> I don't know. Maybe. I'd certainly prefer @rvalue, since it 
> would be clearer (and slightly shorter for that matter), and I 
> don't really agree with copy constructors requiring @implicit 
> anyway. But at the moment, I don't see a technical reason why 
> the attribute couldn't be reused.
>

I find the DIP addresses this in a cleaner way with opt-out.
1) Avoids adding more UDA:s
2) It's probably more common to wish to use this feature than the 
opposite, i.e. by taking the opt-out route we can significantly 
reduce @uda clutter.

See DIP:
> void lval_only(int x) @disable;
> void lval_only(ref int x);
>
> int x = 10;
> lval_only(x);  // ok: choose by-ref
> lval_only(10); // error: literal matches by-val, which is 
> @disabled




More information about the Digitalmars-d mailing list