SafeInt.opCast

Convert this value to type M using checkedint.to() for bounds checking. An IntFlag will be raised if M cannot represent the current value of this SafeInt.

  1. M opCast()
  2. M opCast()
  3. M opCast()
    struct SafeInt(N, IntFlagPolicy _policy, Flag!"bitOps" bitOps = Yes.bitOps)
    const @safe
    M
    opCast
    (
    M
    )
    ()
    if (
    isIntegral!M
    ||
    isSomeChar!M
    )
    if (
    isIntegral!N &&
    )

Examples

import checkedint.sticky : SafeInt; // use IntFlagPolicy.sticky

SafeInt!ulong n = 52uL;
auto a = cast(int)n;
static assert(is(typeof(a) == int));
assert(!IntFlags.local);
assert(a == 52);

auto m = SafeInt!long(-1).mulPow2(n);
auto b = cast(wchar)m;
static assert(is(typeof(b) == wchar));
assert(IntFlags.local.clear() == IntFlag.negOver);

Meta