What is the case against a struct post-blit default constructor?

Timon Gehr timon.gehr at gmx.ch
Thu Oct 11 12:49:49 PDT 2012


On 10/11/2012 02:19 PM, Andrei Alexandrescu wrote:
> [snip good points.]
>

Those should be in the faq.

>
>> Really, there does not seem to me to be any point in having an invariant
>> for a struct, without a default constructor.
>
> Could you please give a few examples? (Honest question.) Most structures
> I define have an obvious quiescent state that vacuously satisfies the
> invariant. Exceptions that come to mind are: (a) value types that must
> always allocate something on the heap, see e.g. the contortions in
> std.container; (b) values as permits (the existence of the value
> guarantees a resource has been secured, as in scoped locks on mutexes).
>
>
> Andrei

I presume that many structures you define are templated and how obvious
their default state is often depends on the particular instantiation. A
large fraction of structs are local in idiomatic D code because of
local template instantiation.

Local structs do not have an obvious valid default state outside their
local context and there is no way to tell if it is valid in generic
code. Therefore, the issues you mentioned remain.


More information about the Digitalmars-d mailing list