mp_units::utility::operator+

Adds a safe_int to an integral scalar, checking for overflow.

Synopsis

Declared in <mp-units/utility/safe_int.h>

template<typename U>
requires (detail::integral<U> && detail::same_sign_v<U, T>)
[[nodiscard]]
constexpr
safe_int</* implementation-defined */, ErrorPolicy>
operator+(
    U lhs,
    safe_int rhs);

NOTE

This function is a hidden friend of safe_int, declared only inside that class: it can be found only through argument-dependent lookup.

Return Value

the sum, as a safe_int of the promoted result type; triggers ErrorPolicy::on_overflow on overflow

NOTE

The return value should not be discarded.

Template Parameters

NameDescription
Uthe integral scalar type

Parameters

NameDescription
lhsthe integral scalar operand
rhsthe safe_int to add