SafeInt.opAssign

Assign the value of that to this SafeInt instance.

Trying to assign a value that cannot be proven at compile time to be representable by N is an error. Use checkedint.to() to safely convert that with runtime bounds checking, instead.

  1. this(const M that)
  2. typeof(this) opAssign(const M that)
    struct SafeInt(N, IntFlagPolicy _policy, Flag!"bitOps" bitOps = Yes.bitOps)
    ref
    typeof(this)
    opAssign
    return pure @safe nothrow @nogc
    (
    M
    )
    (
    const M that
    )
    if (
    isCheckedInt!M ||
    isScalarType!M
    )
    if (
    isIntegral!N &&
    isUnqual!N
    )

Examples

1 import checkedint.sticky : SafeInt, to; // use IntFlagPolicy.sticky
2 
3 // Only types that for which N can represent all values are accepted directly:
4 SafeInt!int n = int.max;
5 n = byte.max;
6 n = wchar.max;
7 
8 // Values of a type that could be `< N.min` or `> N.max` are rejected at compile time:
9 static assert(!__traits(compiles, n = long.max));
10 static assert(!__traits(compiles, n = uint.max));
11 static assert(!__traits(compiles, n = real.max));
12 
13 // Instead, use checkedint.to(), which does runtime bounds checking:
14 n = to!int(315L);
15 assert(n == 315);
16 
17 n = to!int(long.max);
18 assert(IntFlags.local.clear() == IntFlag.posOver);

Meta