Constancy of invariants

Daniel Murphy yebblies at nospamgmail.com
Sun Jan 29 08:46:35 PST 2012


> On discovering that DMD (2.057) rejects
>     invariant() const {}
> I had made out that constancy doesn't apply to invariants.  Only later did 
> I realise it does, but requires the syntax
>     const invariant() {}
Rejecting the first one is just a parser bug.

> Notice also that DMD rejects two or more invariants in a single type
There is an open pull to allow multiple invariants... but not overloading 
them.  It just concatenates them, like unit tests.

> And what's your view?  Should we make invariants automatically const?
Yes, probably.  Once downside is that any private methods you want to call 
will need to be const-correct.  Invariants being const is much less 
restricting than forcing them to be pure/nothrow/safe. 




More information about the Digitalmars-d mailing list