On 06/01/2016 12:59 PM, Mark Isaacson wrote:
I'm trying to create a type that for all intents and purposes behaves
exactly like an int except that it limits its values to be within a
certain range [a,b].

'alias this' with property functions work at least for your example:


struct FixedRangeInt {
    int min;
    int max;
    int i_;

    int value() const {
        return i_;
    }

    void value(int i) {
        assert(i >= min);
        assert(i < max);
        i_ = i;
    }

    alias i_ this;
}

void main() {
    auto f = FixedRangeInt(0, 100);
    f += 2;
    assert(f == 2);
}

Ali

Reply via email to