DIP1000: The return of 'Extend Return Scope Semantics'

Dennis dkorpel at gmail.com
Sat Jun 12 18:35:02 UTC 2021


On Saturday, 12 June 2021 at 18:18:18 UTC, Ola Fosheim Grøstad 
wrote:
> So basically it works if one always transfer smart pointers by 
> value.

You can pass them by `ref`, which is like a non-null pointer with 
built-in `scope`. So if you have a `ref scope int*`, you actually 
have two layers of `scope`: both the pointer variable and the 
pointed-to-object have a restricted lifetime. You can't take the 
address of a `ref scope int*` though, since that would result in 
a double-scope `int**` which dip1000 can't express.

> Although, something like a linked list would not work as it 
> isn't transitive and there is no way to make it transitive? Or?

If you give public access to the `Node* next` member, then you 
can freely escape `node.next.next` indeed. If you encapsulate it 
and only allow accessing nodes through `return scope` member 
functions, then you can make a fully `scope` linked list with 
e.g. all the nodes allocated on the stack.


More information about the Digitalmars-d mailing list