Creating a "fixed-range int" with opDispatch and/or alias this?
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 2 08:07:14 PDT 2016
On 06/02/2016 04:59 PM, Ali Çehreli wrote:
> '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
>
The `value` methods are never called here. The checks are not performed.
More information about the Digitalmars-d-learn
mailing list