TrySub

Subtract j from i in place, only if it does not underflow.

Synopsis

Declared in <util/overflow.h>

template<
    std::unsigned_integral T,
    std::unsigned_integral U>
[[nodiscard]]
constexpr
bool
TrySub(
    T& i,
    U const j) noexcept;

Return Value

true if i >= j and the subtraction was applied, false if it was left unchanged.

NOTE

The return value should not be discarded.

Parameters

NameDescription
iThe minuend, updated to i - j when the subtraction succeeds.
jThe amount to subtract.