Unary plus operators

Synopses

Declared in <mp‐units/utility/constrained.h>

Applies unary + to the wrapped value

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

Adds a safe_int to a floating‐point value.

[[nodiscard]]
constexpr
auto
operator+(
    U lhs,
    safe_int rhs)
requires requires { lhs + static_cast<U>(rhs.value_); };

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

Adds a floating‐point value to a safe_int.

[[nodiscard]]
constexpr
auto
operator+(
    safe_int lhs,
    U rhs)
requires requires { static_cast<U>(lhs.value_) + rhs; };

Computes the sum of lhs and rhs.

Adds a safe_int to a constrained value

Adds a non‐integral constrained value to a safe_int

Adds a constrained value to a safe_int

Adds a safe_int to a non‐integral constrained value

Return Value

  • the wrapped result of applying unary + to x

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

  • the sum of lhs and the wrapped value

  • the sum of the wrapped value and rhs

  • the sum of lhs and rhs; triggers ErrorPolicy::on_overflow on overflow

  • the wrapped sum of the underlying values

Note

The return value should not be discarded.

Template Parameters

Name

Description

U

the integral scalar type

Parameters

Name

Description

x

the wrapped value to apply unary + to

lhs

the integral scalar operand

rhs

the safe_int to add

Created with MrDocs