Compile time range checking/asserts

bearophile bearophileHUGS at lycos.com
Wed Sep 15 05:28:19 PDT 2010


> - Doesn't act transparently as a int subclass;
> - Syntax-wise it's longer to define;
> - The invariant is not enforced in all situations.

And the compiler in most situations doesn't "run" the invariant at compile time (unless you define an enum).

Well, a test shows that it doesn't work (dmd 2.048) even if you use enum, I don't know why:

struct Foo {
    int x;
    this(int y) { this.x = y; }
}
void main() {
    enum Foo f = Foo(1);
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list