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)
    M
    opCast
    const @safe
    (
    M
    )
    (
    )
    if (
    isCheckedInt!M ||
    isIntegral!M
    ||
    isSomeChar!M
    )
    if (
    isIntegral!N &&
    isUnqual!N
    )

Examples

1 import checkedint.sticky : SafeInt; // use IntFlagPolicy.sticky
2 
3 SafeInt!ulong n = 52uL;
4 auto a = cast(int)n;
5 static assert(is(typeof(a) == int));
6 assert(!IntFlags.local);
7 assert(a == 52);
8 
9 auto m = SafeInt!long(-1).mulPow2(n);
10 auto b = cast(wchar)m;
11 static assert(is(typeof(b) == wchar));
12 assert(IntFlags.local.clear() == IntFlag.negOver);

Meta