WithNaN.hookOpCast

If rhs is WithNaN.defaultValue!Rhs, returns WithNaN.defaultValue!Lhs. Otherwise, returns cast(Lhs) rhs.

struct WithNaN
static
Lhs
hookOpCast
(
Lhs
Rhs
)
(
Rhs rhs
)

Parameters

rhs Rhs

the value being cast (Rhs is the first argument to Checked)

Lhs

the target type of the cast

Return Value

Type: Lhs

The result of the cast operation.

Examples

auto x = checked!WithNaN(422);
assert((cast(ubyte) x) == 255);
x = checked!WithNaN(-422);
assert((cast(byte) x) == -128);
assert(cast(short) x == -422);
assert(cast(bool) x);
x = x.init; // set back to NaN
assert(x != true);
assert(x != false);

Meta