Huh, invariant() {...} ?

Kristian Kilpi kjkilpi at gmail.com
Mon Jun 18 11:17:47 PDT 2007


This is a small detail, but I found myself wondering why the class  
invariant declarations have now parenthesis (in 2.0, that is).

I mean, you cannot write something like this:

   invariant {
     int* p;  //invariant int* p;
   }

Or can you?


The class invariant declarations are no longer consistent with other class  
blocks, which is a shame.

   class A {
     invariant() {  //hmmm, should I put parens here or not?
       ...
     }
     unittest {  //how about here?
       ...
     }
   }


It may be clearer anyway to use different keyword for the class  
invariants, 'classinvariant' or something.

Or change the new 'invariant' keyword to 'invar'...

   const int* p1;
   invar int* p2;

(Less typing, and then both the keywords would be 5 chars long (a little  
bonus).)



More information about the Digitalmars-d mailing list