DIP69 - Implement scope for escape proof references

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 9 08:25:12 PST 2014


On 12/9/14 9:23 AM, Nick Treleaven wrote:
> On 08/12/2014 15:53, Steven Schveighoffer wrote:
>>>    scope ref int foo(ref int x);
>>>
>>> will do it.
>>
>> So:
>>
>> int x;
>>
>> foo(x) += 1;
>>
>> will compile?
>
> Yes, because foo's argument is not scope, it can be returned.

But I thought if you take a reference from the stack, it's inferred as 
scope? I feel like there's a missing link somewhere if the scope is 
missing from the parameter.

Will ref just automatically bind to any scoped reference?

What about this:

auto y = &x;

foo(*y) += 1;

-Steve


More information about the Digitalmars-d mailing list