Challenge: write a reference counted slice that works as much as possible like a built-in slice
deadalnix
deadalnix at gmail.com
Wed Nov 10 13:48:53 UTC 2021
On Tuesday, 9 November 2021 at 17:04:29 UTC, Paul Backus wrote:
> Here's a basic sketch of the scheme I had in mind:
> https://gist.github.com/run-dlang/d1982a29423b2cb545bc9fa452d94c5e
>
> It's entirely possible I've overlooked something and this is
> actually unsound. As Andrei says: "destroy!"
There are a few problems with the code, indeed.
1/ You need to add runtime check, because in D, destructed
objects may not have been constructed, so you need to be able to
destroy .init . in your case, pointers will be null and you'll
segfault.
2/ For a struct, you cannot guarantee that the struct's method
don't escape the struct pointer, so none of this can be safe in
any way.
More information about the Digitalmars-d
mailing list