Go, D, and the GC
Dmitry Olshansky via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 5 00:49:08 PDT 2015
On 05-Oct-2015 10:40, deadalnix wrote:
>> In C++ you can't - not only self-references are permitted but also
>> there is no T.init so there is no bit-pattern that is guaranteed to
>> not explode in dtor.
>>
>
> Guaranteed construct/destruction is actually a desirable feature IMO.
> You get all kind of extra case int he dtor to care for when you can't
> ensure proper construction, and it is not always possible to have a
> meaningful .init value, leading to many useless runtime checks or an
> invalid dtor.
>
Yes and no, if your type is movable in C++ you have to have a T.init
equivalent to leave something behind after move (oops!).
Now if the type is not movable it doesn't really burden much to have an
invalid state and trigger an assert in dtor to make sure the type is
properly initialized. Then:
T a; // would trigger assert on dtor
T a = T(...); // shouldn't
If all states are valid and you still want to guarantee construction
that gets tricky. For example for "seconds" struct if we allow negative
seconds as in diff of time. (Though I'd just use long.min for the
"wrong" flag in this case).
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list