The next iteration of scope

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 05:24:11 PDT 2015


On 16/03/2015 04:00, Zach the Mystic wrote:
> struct RC(T) if(is(T == class)) {
>      scope T payload;
>      T borrow() return {    // `return` applies to `this`
>          return payload;
>      }
> }
...
> Also, what exactly does the `scope` on T payload get you?

It means if you forget the `return` attribute the compiler would issue 
an error about escaping payload. payload only has to be annotated once 
and the whole body of RC is checked to prevent implicit escaping of it.




More information about the Digitalmars-d mailing list