WithNaN.hookOpUnary

Defines hooks for unary operators -, ~, ++, and --.

For - and ~, if v == WithNaN.defaultValue!T, returns WithNaN.defaultValue!T. Otherwise, the semantics is the same as for the built-in operator.

For ++ and --, if v == WithNaN.defaultValue!Lhs or the operation would result in an overflow, sets v to WithNaN.defaultValue!T. Otherwise, the semantics is the same as for the built-in operator.

struct WithNaN
static
hookOpUnary
(
string x
T
)
(
ref T v
)

Parameters

x

The operator symbol

v T

The left-hand side of the comparison (T is the first argument to Checked)

Return Value

Type: auto
  • For x == "-" || x == "~": If v == WithNaN.defaultValue!T, the function returns WithNaN.defaultValue!T. Otherwise it returns the normal result of the operator.
  • For x == "++" || x == "--": The function returns void.

Examples

Checked!(int, WithNaN) x;
++x;
assert(x.isNaN);
x = 1;
assert(!x.isNaN);
x = -x;
++x;
assert(!x.isNaN);

Meta