Global invariants?

deadalnix deadalnix at gmail.com
Sat May 12 14:58:24 PDT 2012


Le 12/05/2012 21:37, Alex Rønne Petersen a écrit :
> Hi,
>
> I often find that I'd like to have some sort of 'global invariant', i.e.
> an invariant at module scope (or, more generally, a static invariant).
> So, for example:
>
> private __gshared Mutex lock;
>
> invariant()
> {
> assert(lock);
> }
>
> shared static this()
> {
> lock = new typeof(lock)();
> }
>
> This would be at module level, and the invariant would be called the
> same way it is for member methods, just only in static (free) functions.
> This could of course be generalized to classes and structs.
>
> Is this a good idea?
>

This look awesome !


More information about the Digitalmars-d mailing list