boundedConvert

Convert to given type without errors by bounding values to target type limits.

pure nothrow @safe @nogc
IntTo
boundedConvert
(
IntTo
IntFrom
)
(
IntFrom value
)
if (
isIntegral!IntTo &&
isIntegral!IntFrom
)

Examples

assert((0).boundedConvert!uint == 0u);
assert((42).boundedConvert!uint == 42u);
assert((int.max).boundedConvert!uint == cast(uint) int.max);
assert((-1).boundedConvert!uint == 0u);

Meta