mp_units::utility::constrained

A transparent wrapper that carries an error policy for domain constraint enforcement.

Synopsis

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

template<
    typename T,
    ConstraintPolicy ErrorPolicy = throw_policy>
class constrained;

Description

This wrapper does not check anything itself. It serves as a signal to the mp-units library that domain constraint violations should be reported via the ErrorPolicy rather than through precondition checks.

All arithmetic operations are forwarded to the underlying type T.

Type Aliases

NameDescription
error_policy The policy used to report domain constraint violations
value_type The underlying representation type

Member Functions

NameDescription
constrained [constructor]Constructors
operator%= Assigns the wrapped value to its remainder with respect to rhs.
operator*= Multiplies the wrapped value by rhs.
operator++ Increment operators
operator+= Adds rhs to the wrapped value.
operator-- Decrement operators
operator-= Subtracts rhs from the wrapped value.
operator/= Divides the wrapped value by rhs.
value The wrapped underlying value.
operator T Implicitly converts back to the underlying representation type.

Data Members

NameDescription
value_ The wrapped underlying value

Friends

NameDescription
mp_units::utility::operator-Negates the wrapped value
mp_units::utility::operator+Applies unary + to the wrapped value

Non-Member Functions

NameDescription
operator%Computes the remainder of dividing a constrained value by a safe_int
operator*Multiplies a constrained value by a safe_int
operator*Multiplies a safe_int by a non-integral constrained value
operator*Multiplies a non-integral constrained value by a safe_int
operator+Adds a constrained value to a safe_int
operator+Adds a safe_int to a non-integral constrained value
operator+Adds a non-integral constrained value to a safe_int
operator-Subtracts a safe_int from a non-integral constrained value
operator-Subtracts a safe_int from a constrained value
operator-Subtracts a non-integral constrained value from a safe_int
operator/Divides a non-integral constrained value by a safe_int
operator/Divides a safe_int by a non-integral constrained value
operator/Divides a constrained value by a safe_int

Template Parameters

NameDescription
Tthe underlying representation type
ErrorPolicypolicy type satisfying ConstraintPolicy (provides static on_constraint_violation(std::string_view))