Binding rvalues to ref parameters redux

Olivier FAURE couteaubleu at gmail.com
Thu Mar 28 23:40:45 UTC 2019


On Thursday, 28 March 2019 at 20:11:26 UTC, Andrei Alexandrescu 
wrote:
> The nonassignable requirement is a major improvement, but won't 
> catch all potential misuses. I don't know how to do better.

You could be more strict and consider that any call of the form

     applyDiscount(x.price)

is invalid if `price` is a method, whether or not that method is 
a property. The correct way to pass price's return would then be:

     applyDiscount(x.price())

This syntax is a little surprising to readers because D users 
don't expect empty parentheses for function calls, but I'd count 
that as a plus: this situation is a little ambiguous, so code 
that makes the user wonder about what it does instead of taking 
it for granted is good.

Additionally, you can probably skip the nonassignable requirement 
for const references.


More information about the Digitalmars-d mailing list