syntax question on "invariant" keyword
Daniel919 at web.de
Tue Jul 3 16:17:30 PDT 2007
Are you using dmd 1.x ? The final-const-invariant thing only works on
the experimental 2.x version. I tried your example there and it compiles
without errors as expected.
> Also, http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=8217 claims that "invariant int" and "invariant(int)" are NOT the same, but "invariant int" and "final invariant(int)" are the same.
> I don't know if that is true.
"invariant(int) x" this is useless and does not mean that x can't be
changed, what someone might think at first.
Using brackets means that you can assign another instance of TYPE to the
variable. But you can't change the data of the instance.
"invariant(int) x" means: you can assign another instance of int to x
You see, this doesn't make sense.
It's equal useless for all simple storage classes.
However, "final invariant(int) x = 1" works like "invariant int x = 1",
because final means: you can't assign another int to x
More information about the Digitalmars-d-learn