April 30, 2015 Re: Create custom data types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | Another possible way is to check the bounds at compile time. The different operators need to be overloaded for that. For example, if you have to types Int!(0, 100) and Int!(20, 30), the result type of an addition needs to be Int!(20, 130). Then, there can be an overloaded opCast() to bool for use with if(): Int!(20, 130) i; if(auto j = i.checkBounds(20, 32)) { static assert(is(typeof(j) == Int!(20, 32))); } |
Copyright © 1999-2021 by the D Language Foundation