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)));
}

Reply via email to