1 import checkedint.sticky : safeOp; // safeOp.cmp() never throws 2 3 assert(safeOp.cmp!"=="(int.max, 0x7FFF_FFFF)); 4 assert(safeOp.cmp!"!="(uint.min, 5u)); 5 assert(safeOp.cmp!"<="(int.min, 0)); 6 7 static assert(!__traits(compiles, safeOp.cmp!"=="(uint.max, -1))); 8 static assert(!__traits(compiles, safeOp.cmp!">"(-1, 1u)));
Compare left and right using op.
Unsafe signed/unsigned comparisons will trigger a compile-time error. Possible solutions include:
Direct comparisons between boolean values and numeric ones are also forbidden. Make the intent explicit: