On 6/2/15 11:19 AM, Jonathan M Davis wrote:
On Tuesday, 2 June 2015 at 18:05:20 UTC, Namespace wrote:
AFAIK Andrei wanted 'auto ref' as the syntax which accepts both,
lvalues and rvalues. That's why I'm asking if the current behaviour
for auto ref for templates should change, or not. If not, we have (as
you said) two meanings of auto ref, what is not optimal, but not so
bad either (IMO).
But if I had the choice, I would change it for both, so that both
create a temporary variable for rvalues.
Andrei originally wanted auto ref to apply to non-templated functions,
but Walter misunderstood what he meant and created what we have now -
which is actually incredibly useful, because it allows you to forward
the attributes of an argument - in particular, it's ref-ness. So, we
definitely do _not_ want to lose that.
Yah, auto ref for templates is great. We only need to add auto ref for
non-templates with the semantics "like ref, except (a) accepts rvalues
on the caller side, (b) does not allow escaping the ref from the function".
Note that __traits(isRef, param) doesn't work in an auto ref param in a
non-template function (attempt to use must be a compile-time error).
That's about it.
Andrei