<div dir="ltr">On 9 May 2013 17:26, Peter Alexander <span dir="ltr"><<a href="mailto:peter.alexander.au@gmail.com" target="_blank">peter.alexander.au@gmail.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 Thursday, 9 May 2013 at 04:00:55 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Perhaps you're arguing that the problem is that the user _isn't_ getting<br>
compiler complaints when the code is changed? The call that modifies it<br>
will still work fine, but it will obviously apply the changes to a temp<br>
that is then lost? Surely this is to be expected?<br>
</blockquote>
<br></div>
The call will not still work fine in C++.<br>
<br>
Here's the code again:<div class="im"><br>
<br>
class Collection(T) {<br>
  ref T opIndex(size_t i) { ... }<br>
  ...<br>
}<br>
<br></div><div class="im">
void fix(ref double x) { if (isnan(x)) x = 0; }<br>
<br></div><div class="im">
void fixAll(Collection!double c) {<br>
  foreach (i; 0 .. c.length) {<br>
    fix(c[i]);<br>
  }<br>
}<br>
<br>
<br></div>
In (analogous) C++, if Collection's opIndex changes to return by value then the call to fix is a compile time error (the rvalues don't bind to unqualified ref). I believe Andrei is arguing that D must _at least_ do this to make progress, i.e. not be "worse" (than C++).<br>

</blockquote></div><br></div><div class="gmail_extra" style>Ah yes, right, C++ fix() would need to be 'const ref&', but we decide in D that 'ref const()' is too restrictive.</div><div class="gmail_extra" style>
<br></div><div class="gmail_extra" style>We're about 1 post away from finding ourselves arguing over 'scope ref'/'auto ref' again...</div></div>