On Monday, 22 June 2015 at 13:49:31 UTC, Jonathan M Davis wrote:
On Monday, 22 June 2015 at 13:23:47 UTC, Marc Schütz wrote:
On Monday, 22 June 2015 at 04:11:41 UTC, Andrei Alexandrescu
wrote:
Walter and I discussed what auto ref for templates should
look like and reached the conclusion that an approach based
on lowering would be best. I added a proposed lowering to
https://github.com/D-Programming-Language/dmd/pull/4717.
I have to concur with Manu's statement in the PR. IMO `auto
ref` (i.e. the status quo) is a hack introduced because of the
lack of usable `scope`. We shouldn't spread it to other parts
of the language, at least not for rvalue references. `scope
ref` is the perfect fit for those.
(There may still be a use for `auto ref` with the meaning
"pass this as efficiently as possible, I don't care whether
it's a reference or not", but I'm not convinced of that
either.)
I'm afraid that I don't understand this. What on earth does
scope have to do with this issue? We need a way to indicate
that a parameter should accept both lvalues and rvalues.
`scope` is a precondition for doing this safely. As Manu pointed
out, rvalues are merely a special case of a more general problem,
but with them, the risk of misuse is much higher than with local
variables. That was probably the reason why `ref` originally was
designed not to accept rvalues. Given a working `scope` feature,
that reason is no longer relevant, therefore `scope ref` can
safely accept both rvalues and lvalues.