The OpenD Programming Language

Checked.opCast

Casting operator to integral, bool, or floating point type.

If a cast to a floating-point type is requested and Hook defines onBadCast, the cast is verified by ensuring get == cast(T) U(get). If that is not true, hook.onBadCast!U(get) is returned.

If a cast to an integral type is requested and Hook defines onBadCast, the cast is verified by ensuring get and cast(U) get are the same arithmetic number. (Note that int(-1) and uint(1) are different values arithmetically although they have the same bitwise representation and compare equal by language rules.) If the numbers are not arithmetically equal, hook.onBadCast!U(get) is returned.

struct Checked(T, Hook = Abort)
U
opCast
(
U
this _
)
()
if (
is(U == bool)
)
if (
is(T == Checked!(U, H),
U
H
)
)

Parameters

U

The type to cast to

Return Value

Type: U

If Hook defines hookOpCast, the call immediately returns hook.hookOpCast!U(get). Otherwise, casting to bool yields get != 0 and casting to another integral that can represent all values of T returns get promoted to U.

Examples

assert(cast(uint) checked(42) == 42);
assert(cast(uint) checked!WithNaN(-42) == uint.max);

Meta