C++ pattern matching is coming

Walter Bright newshound2 at digitalmars.com
Mon Oct 24 04:26:21 UTC 2022


On 10/23/2022 6:50 PM, Timon Gehr wrote:
> It kind of does a bit with return annotations:
> 
> ```d
> int* foo(return scope int* x)@safe{
>      auto y=x;
>      int t;
>      auto z=&t;
>      return y; // ok, but can't return z
> }
> ```

It isn't actually tracking lifetimes, it just copies the attributes from x to y. 
z gets the scope attribute because it is initialized with the address of a stack 
variable.


> I guess my issue here is that @live, while it may use some methods that may be 
> helpful in another context, does not enable any of the use cases I described 
> either. It does not make @safe any safer and it also does not make DIP1000 any 
> more modular.

@live's purpose is to prevent:

1. use after free
2. multiple free's
3. no free

To go further than that will require the user to construct a container that 
encapsulates whatever it does, and is likely going to include some @trusted 
functionality. Which is more or less what Rust does.


> I agree that it is quite useful for some cases. It just does not seem to offer 
> all that much yet in terms of actually enabling safe manual memory management 
> for the entire application.

Without the 1,2,3 above, you're right that DIP1000 is not a complete solution. 
But it is a necessary precondition for doing 1,2,3.



More information about the Digitalmars-d mailing list