The comparison operator, must be either >, < , <= or >=. Equality is also allowed even if this is always a transparent operation.
The left operand, an integer.
The right operand, an integer.
A bool, the comparison result.
1 int a = -1; uint b; 2 assert(a > b); // wrong result 3 assert(compare!">"(a,b) == false); // fixed by operand widening 4 assert(b < a); // wrong result 5 assert(compare!"<"(b,a) == false); // fixed by operand widening 6 7 long aa = -1; ulong bb; 8 assert(aa > bb); // wrong result 9 assert(compare!">"(aa,bb) == true); // not statically fixable 10 assert(bb < aa); // wrong result 11 assert(compare!"<"(bb,aa) == true); // not statically fixable 12 13 assert(compare!"!="(bb,aa) == true); // test for equality is always transparent OP 14 15 immutable long aaa = -1; const ulong bbb; 16 assert(compare!">"(aaa,bbb) == true);
Compares two integral values with additional static checkings.
If the comparison mixes signed and unsigned operands then the function tries to widen the unsigned operand to perform a valid comparison, otherwise a DMD-style warning is emitted.