[dmd-beta] rvalue references

Jason House jason.james.house at gmail.com
Thu Apr 12 16:34:20 PDT 2012


On Apr 12, 2012, at 5:50 PM, Andrei Alexandrescu <andrei at erdani.com> wrote:

> 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.

You could still allow binding to const ref parameters.


More information about the dmd-beta mailing list