auto ref is on the docket

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 22 13:56:11 PDT 2015


On Monday, 22 June 2015 at 20:42:58 UTC, Daniel N wrote:
> Considering we already have working 'Sealed references', why 
> not simply allow rvalues for plain ref?

Please, please, no. That would be horrible. ref indicates an 
intention to mutate the argument, which makes no sense with 
rvalues. And if ref is used simply so that you can accept both 
rvalues and lvalues without copying lvalues, then there's zero 
indication in the function signature when the point of the ref is 
to actually set what's being passed in.

It works in C++ with const&, because you know that the function 
won't mutate the argument, but if you allow it with ref in 
general, then you stand no chance of being able to look at a 
function signature and deduce whether the function intends to 
mutate an argument or not. And even if Andrei wasn't so set 
against const ref that we could go that route in D as well, it 
wouldn't solve the problem either, because const in D is just too 
restrictive to use in many cases. We need a way to indicate that 
a parameter accepts both lvalues and rvalues without intending to 
mutate the argument but without actually guaranteeing it via 
const. And that does _not_ work with naked ref.

- Jonathan M Davis


More information about the Digitalmars-d mailing list