RAII pointers
Moritz Maxeiner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 3 12:37:48 PDT 2017
On Saturday, 3 June 2017 at 19:21:58 UTC, ag0aep6g wrote:
> On 06/03/2017 09:06 PM, Moritz Maxeiner wrote:
>> - null check in destructor: That's just because I forgot to
>> add it. If you add `@disable(this)` (disable the default
>> constructor), all elaborate constructors ensure it is not
>> null, and no members can set it to null, you might be able to
>> skip the check, but I may have missed some corner cases, so
>> better be safe.
>
> `.init` is the corner case. `.init` is always there, even with
> `@disable this();`.
Of course, but AFAIK you'd need to explicitly assign it to an
object, so `ptr` won't null by accident, but only by explicit
programmer intent (same as overwriting the memory the object
lives in via things like `memcpy`); and you can always screw
things intentionally (you could also assign some invalid value to
the pointer via `memcpy`).
Are there any accidental corner cases?
More information about the Digitalmars-d-learn
mailing list