On Thursday, 9 May 2013 at 04:00:55 UTC, Manu wrote:The call will not still work fine in C++.
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?
Here's the code again:
class Collection(T) {
ref T opIndex(size_t i) { ... }
...
}
void fix(ref double x) { if (isnan(x)) x = 0; }
void fixAll(Collection!double c) {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++).
foreach (i; 0 .. c.length) {
fix(c[i]);
}
}