1 import checkedint.sticky : smartOp; // use IntFlagPolicy.sticky 2 3 assert(smartOp.unary!"~"(0u) == uint.max); 4 5 auto a = smartOp.unary!"-"(20uL); 6 static assert(is(typeof(a) == long)); 7 assert(a == -20); 8 9 auto b = smartOp.unary!"+"(uint.max); 10 static assert(is(typeof(b) == int)); 11 assert(IntFlags.local.clear() == IntFlag.posOver); 12 13 uint c = 1u; 14 assert(smartOp.unary!"--"(c) == 0u); 15 assert(c == 0u); 16 smartOp.unary!"--"(c); 17 assert(IntFlags.local.clear() == IntFlag.negOver); 18 19 int d = 7; 20 assert(smartOp.unary!"++"(d) == 8); 21 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.