<div dir="ltr">On 7 May 2013 00:26, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</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 5/6/13 12:56 PM, Steven Schveighoffer wrote:<br>

<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">
On Sat, 04 May 2013 22:49:42 -0700, Andrei Alexandrescu<br>
<<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a><u></u>> wrote:<br>
<br>
<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">
void fix(ref double x) { if (isnan(x)) x = 0; }<br>
</blockquote>
<br>
...<br>
<br>
<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">
There may be other important patterns to address at the core, please<br>
chime in. I consider (1) above easy to tackle, which leaves us with at<br>
least (2). My opinion is that any proposal for binding rvalues to ref<br>
must offer a compelling story about these patterns.<br>
</blockquote>
<br>
But there are reasons to bind rvalues to references. I think deadalnix<br>
said it best, when you want to use ref to modify values, generally you<br>
want rvalues to be rejected (though I think rvalue is not a good<br>
description, consider that a pointer is an rvalue, but what it points to<br>
is an lvalue). When you want to use ref to avoid expensive copies, you<br>
want rvalues to be accepted.<br>
</blockquote>
<br></div>
Yah, so that's why I'm thinking "auto ref" would fit the bill there. Requiring pointers for lvalue binding and binding loosely to ref seems like the wrong move.</blockquote><div><br></div><div style>... I feel like this discussion has jumped about 1 week back in time :/</div>
<div style><br></div><div style>In 1) "<span style="font-family:arial,sans-serif;font-size:13px">If rvalues bind indiscriminately to ref,</span><span style="font-family:arial,sans-serif;font-size:13px"> </span><span style="font-family:arial,sans-serif;font-size:13px">then the call is legal because of the implicit conversion float->double"</span></div>
<div style><font face="arial, sans-serif">Implicit conversion should never be allowed when receiving by ref, just like it's an error in C++. There should never be a case where, having passed an lvalue, the function receives a magic temp from an implicit conversion.</font></div>
<div style><font face="arial, sans-serif">C++ correctly doesn't allow this, but lots of people here seem to think it does...</font></div><div style><font face="arial, sans-serif"><br></font></div><div style><font face="arial, sans-serif">In 2) "</font><span style="font-family:arial,sans-serif;font-size:13px">Changing return types from ref T to T or back and expecting no ill effects (aside from fixing compile-time errors) is a frequent operation in C++ projects I'm involved in. Doing worse than that would be arguably a language design regression."</span></div>
<div style><span style="font-family:arial,sans-serif;font-size:13px">Can you show where you would ever make such a change in C++?</span></div><div style><span style="font-family:arial,sans-serif;font-size:13px">What do you mean by 'worse'? The behaviour is to be expected... if opIndex doesn't return a ref, why would you expect that the caller can possibly change it?</span></div>
<div style><span style="font-family:arial,sans-serif;font-size:13px">I don't see any problem here... what 'ill effects' are you referring to?</span></div><div style><span style="font-family:arial,sans-serif;font-size:13px">Perhaps you're arguing that the problem is that the user _isn't_ getting compiler complaints when the code is changed? The call that modifies it will still work fine, but it will obviously apply the changes to a temp that is then lost? Surely this is to be expected?</span></div>
</div></div></div>