The missing bit in DIP1000

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Thu Jun 23 17:00:58 UTC 2022


On Thursday, 23 June 2022 at 16:43:21 UTC, Ola Fosheim Grøstad 
wrote:
> ```
> void connect(scope!1(node)* a, (scope!1(node)|scope!2(node))* 
> b){
>   a.next = b;
> }
>
> ```

Thinking aloud, so I guess this also makes it possible to get rid 
of the return scope ref thing:

```
  scope!1(node)* connect(scope!1(node)* a, 
(scope!1(node)|scope!2(node))* b){
    a.next = b;
    return a;
  }

  auto tmp = x.connect(y).connect(z);
```

The caller now knows that the returned pointed to object has the 
same life time as the first parameter it provided.

You could have some simple aliases like:
```
  scope(x) :=: scope!0(x)
  scope1(x) :=: scope!1(x)
  scope2(x) :=: scope!2(x)
  scope12(x) :=: scope!1(x)|scope!2(x)
```

or something like that, then the previous example would be:

```
  scope1(node)* connect(scope1(node)* a, scope12(node)* b){
    a.next = b;
    return a;
  }

  auto tmp = x.connect(y).connect(z);
```

Still got a feeling that standard life times are about the same 
level of complexity.


More information about the Digitalmars-d mailing list