May 12, 2012 Global invariants? | ||||
|---|---|---|---|---|
| ||||
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
| ||||
May 12, 2012 Re: Global invariants? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | 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 !
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply