rvalue references

Zach the Mystic reachzach at gggggmail.com
Sat Apr 27 09:11:27 PDT 2013


On Saturday, 27 April 2013 at 03:29:10 UTC, Diggory wrote:
> I'm starting to think there does need to be new syntax if all 
> three of the above cases are to be covered - it would work just 
> making "ref" accept rvalues but then "move" would be the 
> default for lvalues, and that would be confusing - but I don't 
> think using "scope" solves any problems, as the semantics 
> required for rvalues are orthogonal to what "scope" actually 
> means.

I think 'scope' is yet to be fully defined. Returning a reference 
doesn't necessarily mean escaping unsafely. The primary goal is 
safety. From the perspective of the calling function, something 
assigned 'scope' remains in scope even if it's returned.

scope ref T gin(scope ref T a) { return a; }
void fun() {
   T t;
   gin(t); // It's still in scope
}

The return is in the outer scope still, so 'scope' is not totally 
out of place. But it does seem like it's pushing it, admittedly.


More information about the Digitalmars-d mailing list