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

deadalnix deadalnix at gmail.com
Thu Oct 11 06:56:07 PDT 2012


Le 11/10/2012 14:19, Andrei Alexandrescu a écrit :
> 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).
>

invariant will explode at you face at runtime any time you use the 
struct wrong where a default constructor would have prevented such use 
in the first place.

Worse, the faulty case can be created at any place where the struct is 
used and is likely to create a problem.

In fact, such design rely on the well known « a good programmer don't do 
... » which is known to be a very good way to design hard to use and 
error prone constructs.


More information about the Digitalmars-d mailing list