<div dir="ltr">On 27 April 2013 05:31, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Friday, April 26, 2013 14:15:07 Manu wrote:<br>
> > I mean is that the way that auto ref should work with non-templated<br>
> > functions<br>
> > is that<br>
> ><br>
> > auto foo(auto ref T param) {...}<br>
> ><br>
> > becomes<br>
> ><br>
> > auto foo(ref T param) {...}<br>
> ><br>
> > underneath the hood. Then when you pass an rvalue to it - e.g. foo(T(5)) -<br>
> > that gets translated to something like<br>
> ><br>
> > T __temp = T(5);<br>
> > foo(__temp);<br>
> ><br>
> > Then auto ref works with both lvalues and rvalues with only one function<br>
> > definition, and ref is unchanged in how it works (it still only accepts<br>
> > lvalues).<br>
><br>
> Why bother with 'auto'? Why not just make this default behaviour?<br>
<br>
</div>For the same reason that T& doesn't take rvalues in C++ while const T& does.<br>
There's a big difference between wanting an argument to be passed as efficiently<br>
as possible and specifically wanting to alter the argument being passed 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 one<br>
which takes its argument by auto ref are fundamentally different.<br></blockquote><div><br></div><div style>So you're saying it should be const ref instead of auto ref...</div><div style>I agree.</div></div></div></div>