import checkedint.sticky : smartOp; // use IntFlagPolicy.sticky assert(smartOp.unary!"~"(0u) == uint.max); auto a = smartOp.unary!"-"(20uL); static assert(is(typeof(a) == long)); assert(a == -20); auto b = smartOp.unary!"+"(uint.max); static assert(is(typeof(b) == int)); assert(IntFlags.local.clear() == IntFlag.posOver); uint c = 1u; assert(smartOp.unary!"--"(c) == 0u); assert(c == 0u); smartOp.unary!"--"(c); assert(IntFlags.local.clear() == IntFlag.negOver); int d = 7; assert(smartOp.unary!"++"(d) == 8); assert(d == 8);
Perform the unary (single-argument) integer operation specified by op.
Key differences from the standard unary operators:
Note that like the standard operators, ++ and -- take the operand by ref and overwrite its value with the result.