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

tsbockman thomas.bockman at gmail.com
Wed Nov 10 19:52:25 UTC 2021


On Wednesday, 10 November 2021 at 18:50:26 UTC, Paolo Invernizzi 
wrote:
> On Wednesday, 10 November 2021 at 17:24:03 UTC, deadalnix wrote:
>> On Wednesday, 10 November 2021 at 17:09:05 UTC, H. S. Teoh 
>> wrote:
>>> 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
>>
>> No.
>>
>> Everything that is destructed must have been constructed. It 
>> is the only way you can enforce invariant within a type.
>
> Invariants must hold also with structures initialised from 
> '.init', if you don't want to @disable this()...

The semantics of `struct` `.init` initialization are (nearly) 
equivalent to mandating that `this()` be `pure`, allocate no 
memory, and work in CTFE. This does significantly limit what 
invariants can be established.


More information about the Digitalmars-d mailing list