<div dir="ltr">On 27 April 2013 12:26, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Saturday, April 27, 2013 10:21:32 Manu wrote:<br>

> > > Why bother with 'auto'? Why not just make this default behaviour?<br>
> ><br>
> > For the same reason that T& doesn't take rvalues in C++ while const T&<br>
> > does.<br>
> > There's a big difference between wanting an argument to be passed as<br>
> > efficiently<br>
> > as possible and specifically wanting to alter the argument being passed<br>
> > in.<br>
> > Plain ref is for cases where you explicitly want to mutate the argument.<br>
> > You're just asking for bugs if you allow ref to accept rvalues. We've had<br>
> > problems like this before when some literals were treated as lvalues. The<br>
> > behavior of a function which takes its argument by ref and the behavior of<br>
> > one<br>
> > which takes its argument by auto ref are fundamentally different.<br>
><br>
> So you're saying it should be const ref instead of auto ref...<br>
> I agree.<br>
<br>
</div>Not at all. const is so much more restrictive in D that it really doesn't make<br>
sense to have const be required in order to be able to pass an argument to a<br>
function efficiently without caring whether it's an rvalue or an lvalue. auto<br>
ref permits const but doesn't require it - which is what we need - whereas<br>
const ref is always const.<br>
<br>
I'm arguing that we need an attribute which differs from naked ref which<br>
indicates that the function doesn't care whether it's given an lvalue or an<br>
rvalue - it just wants it to be passed as efficiently as possible. auto ref is<br>
supposed to serve this purpose. Naked ref on the other hand is specifically for<br>
when the function needs to alter the argument and not a copy of the argument.<br>
const ref is ultimately kind of useless IMHO.<br>
<br>
The only real hangup with that at this point is that templated functions<br>
should be able to use the auto ref solution that non-templated functions<br>
should use (invisibly creating a variable when an rvalue is passed so that an<br>
lvalue can be passed), but we also need the current auto ref functionality<br>
that we have for templated functions. So, either we need a new attribute, or<br>
we need to do what Timon suggested and make the compiler smart enough to figure<br>
out when it can get away with using the non-templated auto ref solution with a<br>
templated function without changing the function's semantics.<br></blockquote><div><br></div><div style>I don't see myself ever getting on board with this auto-ref idea. I just think it's crazy. It makes no sense to me, they are completely unrelated concepts. It will only lead to confusion.</div>
<div style><br></div><div style>I'm back at scope-ref. Kenji is right as far as I'm concerned. Not to mention, he actually did the work.</div><div style>It makes perfect sense, and I can't see any reason why auto-ref should be used instead of something that actually makes intuitive sense, and people will eventually want to use anyway...</div>
</div></div></div>