Create custom data types

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 30 04:55:44 PDT 2015


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


More information about the Digitalmars-d-learn mailing list