regarding what seems (to me) unnecessary casts on integer expressions

russhy russhy at gmail.com
Mon Jun 7 12:53:29 UTC 2021


Everything is public by default, and you can't overload and 
derive from structs so final has no effect

there less visual noise:

```D
struct gudtPosition {

    void reset() { pintLeft1 = pintTop1 = pintRight1 = pintBottom1 
= 0; }

    private ushort pintLeft1 = 0;
    private ushort pintTop1 = 0;
    private ushort pintRight1 = 0;
    private ushort pintBottom1 = 0;

    const ushort left1() { return this.pintLeft1; }
    const ushort top1() { return this.pintTop1; }
    const ushort right1() { return this.pintRight1; }
    const ushort bottom1() { return this.pintBottom1; }

    ushort left0() { return this.pintLeft1 = 0 ? 0 : 
cast(ushort)(this.pintLeft1 - 1); }
    ushort top0() { return this.pintTop1 = 0 ? 0 : 
cast(ushort)(this.pintTop1 - 1); }
    ushort right0() { return this.pintRight1 = 0 ? 0 : 
cast(ushort)(this.pintRight1 - 1); }
    ushort bottom0() { return this.pintBottom1 = 0 ? 0 : 
cast(ushort)(this.pintBottom1 - 1); }

    void left1(const ushort lintPosition) { this.pintLeft1 = 
lintPosition; }
    void top1(const ushort lintPosition) { this.pintTop1 = 
lintPosition; }
    void right1(const ushort lintPosition) { this.pintRight1 = 
lintPosition; }
    void bottom1(const ushort lintPosition) { this.pintBottom1 = 
lintPosition; }

    string caption0() { return /// eg: from (24,24) to (48,48)
       r"from ("c ~
       std.format.format(r"%d"c, this.left0) ~
       r","c ~
       std.format.format(r"%d"c, this.top0) ~
       r") to ("c ~
       std.format.format(r"%d"c, this.right0) ~
       r","c ~
       std.format.format(r"%d"c, this.bottom0) ~
       r")"c;
    }

    string caption1() { return /// eg: from (24,24) to (48,48)
       r"from ("c ~
       std.format.format(r"%d"c, this.pintLeft1) ~
       r","c ~
       std.format.format(r"%d"c, this.pintTop1) ~
       r") to ("c ~
       std.format.format(r"%d"c, this.pintRight1) ~
       r","c ~
       std.format.format(r"%d"c, this.pintBottom1) ~
       r")"c;
    }

}
```


More information about the Digitalmars-d-learn mailing list