[dmd-beta] rvalue references

Andrei Alexandrescu andrei at erdani.com
Thu Apr 12 14:50:31 PDT 2012


On 4/12/12 3:11 PM, Dmitry Olshansky wrote:
> Interesting thing with non-escaping ref is that making truly unsealed
> containers is hard while writing sealed ones made easier(and that's a
> good thing btw).

There is a liability here however. Today, people who don't want to allow 
changes to their containers or ranges would routinely return rvalues 
from e.g. front().

If we allow function results to bind to ref parameters, people would 
think they modify stuff when in fact they don't do anything. Consider:

void swap(T)(ref T lhs, ref T rhs);
...
swap(r1.front, r2.front);

The user thinks the fronts of the ranges are swapped but nothing happens.

So we don't want to allow function results (including property results) 
to bind to ref parameters.


Andrei



More information about the dmd-beta mailing list