import checkedint.sticky : SafeInt, to; // use IntFlagPolicy.sticky // Only types that for which N can represent all values are accepted directly: SafeInt!int n = int.max; n = byte.max; n = wchar.max; // Values of a type that could be `< N.min` or `> N.max` are rejected at compile time: static assert(!__traits(compiles, n = long.max)); static assert(!__traits(compiles, n = uint.max)); static assert(!__traits(compiles, n = real.max)); // Instead, use checkedint.to(), which does runtime bounds checking: n = to!int(315L); assert(n == 315); n = to!int(long.max); assert(IntFlags.local.clear() == IntFlag.posOver);
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.