smartOp.cmp

Defines a total order on all basic scalar values, using the same rules as std.math.cmp().

  • Mixed signed/unsigned comparisons return the mathematically correct result.
  • If neither left nor right is floating-point, this function is faster than std.math.cmp().
  • If either left or right is floating-point, this function forwards to std.math.cmp().


Direct comparisons between boolean values and numeric ones are forbidden. Make the intent explicit:

  • numeric == cast(N)boolean
  • (numeric != 0) == boolean
  1. bool cmp(const N left, const M right)
  2. int cmp(const N left, const M right)
    template smartOp(IntFlagPolicy policy)
    int
    cmp
    pure @safe nothrow @nogc
    (
    N
    M
    )
    (
    const N left
    ,
    const M right
    )
    if (
    isScalarType!N &&
    isScalarType!M
    )

Examples

1 import checkedint.sticky : smartOp; // smartOp.cmp() never throws
2 
3 assert(smartOp.cmp(325.0, 325u) == 0);
4 assert(smartOp.cmp(uint.max, -1) == 1);
5 assert(smartOp.cmp(-3156, 300u) == -1);

Meta