Challenge: write a reference counted slice that works as much as possible like a built-in slice

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Nov 10 17:09:05 UTC 2021


On Wed, Nov 10, 2021 at 01:52:26PM +0000, deadalnix via Digitalmars-d wrote:
> On Tuesday, 9 November 2021 at 18:33:01 UTC, Atila Neves wrote:
> > I think that C++'s greatest gift to the world was the destructor. We
> > have those too! Let's use them.
> > 
> 
> Indeed, but I have unfortunate news. We broke the gift. In D, object
> can be destroyed without being constructed first.
> 
> Consider: https://godbolt.org/z/EdW75jWGn
> 
> This is the first problem we need to fix here, if we don't want to
> have to plaster our code with runtime checks.

Isn't that what @disable this() is for?

And to be pedantic, the object *was* constructed -- by the default ctor.
If you didn't want that, you should @disable this().


T

-- 
"The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts." -- Bertrand Russell. "How come he didn't put 'I think' at the end of it?" -- Anonymous


More information about the Digitalmars-d mailing list