On Sunday, 21 April 2013 at 00:51:31 UTC, Manu wrote:It's a two-fer! (2 for 1 deal)
That's not what scope does. Scope promises that the variables will not
escape the scope. And as such, just happens to make passing a temporary by
ref safe.
It does not implement r-value ref's. It simply allows refs to temporaries
to be considered a safe operation.
It's hard to fully understand this example without getMatrix() defined, and why func() is unsafe (does it escape the reference?). Help!
This DIP is actually likely to solve an important source of problems,
consider:
void func(const ref matrix m);
func(x.getMatrix()); // compile error!
// fu*^&%$ing hell! you piece of &%^#≈¿$!
// ...
matrix temp = x.getMatrix();
func(temp); // no more compile error! (but equally unsafe/dangerous)
Yikes.<Side rant>
In my experience showing D to new people, this is the #1 complaint. It's
the first one that comes up, every time (which really doesn't help with
first impressions), and I'm fairly sure every single person I've introduced
to D has complained about this.
It's kind of embarrassing when I'm saying that D is really cool, and then I
have to start making excuses and apologising for this, and assure them that
it's a known issue, and it'll be fixed one day.