The liabilities of binding rvalues to ref

Timon Gehr timon.gehr at gmx.ch
Thu May 9 15:50:37 PDT 2013


On 05/09/2013 11:35 PM, Manu wrote:
> ...
>
> I don't think this is entirely true, auto ref is a template concept,

In the current implementation, but not necessarily.

> that is, "automatic ref-ness", it selects the ref-ness of the argument
> automatically, at compile time, just like auto applied everywhere else
> (selects a type for instance, at compile time).

auto was carried over from C and originally stands for local lifetime. 
It does _not_ mean "apply type deduction here".

> This concept doesn't
> make any sense applied to a non-template. It *IS* a ref as specified by
> the programmer, there's nothing 'automatic' about it.
>

Most keywords are poorly chosen.

> So to say it will do 'exactly the same thing' is a misunderstanding. I
> argue that 'auto ref' as applied to non-templates will only create
> confusion, it effectively re-enforces the type of confusion that you
> have just shown.
>
> This is the reasoning for the argument behind scope ref, which to my
> mind actually makes good sound sense, and should lead people to a proper
> understanding of what you are actually doing.
> Considering the key argument against 'scope ref' is that people don't
> want to require more attributes to make use of it,

This is inaccurate.

> I don't see how 'auto ref' satisfies this argument either.

Sure, it wouldn't.

> Thus, I am quite happy happy with 'ref', it can be made safe, satisfies
> the argument above, and this seems like a very good start that we might
> actually all agree on.

It can make code evolution less straightforward.


More information about the Digitalmars-d mailing list