Global invariants?

Alex Rønne Petersen xtzgzorex at gmail.com
Sat May 12 12:37:18 PDT 2012


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?

-- 
- Alex


More information about the Digitalmars-d mailing list