dmd 1.048 and 2.033 releases

bearophile bearophileHUGS at lycos.com
Mon Oct 5 04:40:01 PDT 2009


Can someone show an usage example of contract inheritance? (where inheritance is useful).


Regarding the fixed bugs 2702 and 2469, I'm having problems still, at the bottom y is 0:

import std.stdio: writeln;
import std.conv: to;

struct Ranged(int RANGED_MIN, int RANGED_MAX) {
    int x_ = RANGED_MIN;

    int x() { return this.x_; }
    int x(int xx) { this.x_ = xx; return xx; }
    alias x this;

    invariant() {
        //assert(this.x_ >= RANGED_MIN, "Ranged value too much small");
        assert(this.x_ < RANGED_MAX, "Ranged value too much big");
    }

    //Ranged opCast(int xx) { return Ranged(xx); }

    string toString() { return to!string(this.x_); }
}

void main() {
    typedef Ranged!(10, 20) ranged;
    ranged x;
    writeln(x);
    //ranged y = 1000; // temp.d(23): Error: cannot implicitly convert expression (1000) of type int to ranged
    ranged y = cast(ranged)100;
    writeln(y); // 0?
}

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list