Challenge: write a reference counted slice that works as much as possible like a built-in slice
Stanislav Blinov
stanislav.blinov at gmail.com
Wed Nov 10 20:35:57 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.
How is that a problem, or, more to the point, how is D breaking
anything here, as compared to C++? The latter effectively works
by convention with its "valid, but unspecified state" for stdlib
moved-from objects, and it's the best it can afford. We won't
have that. The state is specified - it's .init. Right now it's
also a mere convention, but it is effectively going to be set in
stone with the move semantics DIP. It's a huge win as it allows
the language to mandate rules for destructor elision, which C++
can't and won't do. I'd go so far as to argue that in a future
version of D, the code presented above won't be calling a
destructor at all.
More information about the Digitalmars-d
mailing list