C++ pattern matching is coming
Walter Bright
newshound2 at digitalmars.com
Mon Oct 24 22:15:21 UTC 2022
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.
> free(expired.data);
> }
More information about the Digitalmars-d
mailing list