xieite::add_overflow()

Defined in fragment xieite:add_overflow
(header-only: <xieite/math/add_overflow.hpp>)


Checks whether the addition of two or more integers would overflow or underflow their type.
Can be used to catch undefined behavior before it is invoked (such as when the addition of two signed integers would overflow).


Declaration

template<xieite::is_arith T, std::convertible_to<T>... Ts>
[[nodiscard]] constexpr bool add_overflow(T first, Ts... rest) noexcept;


Example

import std;
import xieite;

int main() {
	xieite::dump(xieite::add_overflow<std::int8_t>(127, 1));
}
Output:
true
View in Compiler Explorer