C++ pattern matching is coming

Dukc ajieskola at gmail.com
Tue Oct 25 09:33:36 UTC 2022


On Monday, 24 October 2022 at 22:15:21 UTC, Walter Bright wrote:
> On 10/24/2022 1:58 PM, Dukc wrote:
>> struct MMptr (Pointee)
>> { @system Pointee* data; // Assuming @system variables DIP is 
>> implemented
>>    // implementation...
>> }
>> 
>> // The only way to create MMptrs except for nulls
>> MMptr!T mallocate(T)()
>> { import core.lifetime;
>>    import core.stdc : malloc;
>>    auto mem = cast(T*)malloc(sizeof(T));
>>    return MMptr(mem.emplace);
>> }
>> 
>> // The only way to get rid of owned MMptrs
>> void free(T)(MMptr!T expired)
>> { import core.stdc : free;
>>    destroy!false(*expired.data);
>
> .data wouldn't be accessible from @safe code.

Oh sorry, I wasn't clear. I meant `MMpointer` would enable 
borrowing `.data` from `@safe` code with a member function(s), 
such as
```D
@trusted Pointee* asPtr() return scope {return data;}
@trusted ref Pointee opUnary(string op)() return
   if(op == "*")
{ return *data;
}
```



More information about the Digitalmars-d mailing list