DIP 36: Rvalue References

Manu turkeyman at gmail.com
Sat Apr 20 19:13:41 PDT 2013


On 21 April 2013 11:36, Zach the Mystic <reachzach at gggggmail.com> wrote:

> On Sunday, 21 April 2013 at 00:51:31 UTC, Manu wrote:
>
>> 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 a two-fer! (2 for 1 deal)
>
>
>  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)
>>
>
> It's hard to fully understand this example without getMatrix() defined,
> and why func() is unsafe (does it escape the reference?). Help!


definition:
  matrix getMatrix(T x); // this is all you know

That's the point of the example. You _don't know_ if func() is unsafe, does
it escape the reference? But you need to pass a temp anyway, you have no
bearing on whether you should just hack it to work, or reconsider the
problem.
And when 99 times out of 100, the correct answer is 'hack it to work',
you're basically asking for a spectacular bug in that other 1% of cases.


 <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.
>>
>
> Yikes.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130421/6112fdc2/attachment.html>


More information about the Digitalmars-d mailing list