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

jmh530 john.michael.hall at gmail.com
Wed Nov 10 14:04:18 UTC 2021


On Wednesday, 10 November 2021 at 13:52:26 UTC, deadalnix 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.

The struct is instantiated [1], it just doesn't run the 
constructor in that case. You can always disable the default 
constructor. Doesn't C++ have an implicit default constructor 
also?


[1] https://dlang.org/spec/struct.html#struct-instantiation




More information about the Digitalmars-d mailing list