Add two integers, checking for overflow.

Synopsis

Declared in <util/overflow.h>

template<class T>
[[nodiscard]]
std::optional<T>
CheckedAdd(
    T const i,
    T const j) noexcept;

Return Value

The sum i + j, or std::nullopt if the addition would overflow T.

Note

The return value should not be discarded.

Parameters

Name

Description

i

The first addend.

j

The second addend.

Created with MrDocs