mp_units::safe_int

Wraps an integral type with overflow detection.

Synopsis

Declared in <mp-units/safe_int.h>
template<
    std::integral T,
    OverflowPolicy EP = safe_int_throw_policy>
class safe_int;

Description

This class wraps any integral type and models all requirements for mp-units representation types (RealScalar, MagnitudeScalable, etc.). Every arithmetic operation checks for overflow and delegates to the ErrorPolicy::on_overflow() handler on detection.

Types

Name
error_policy
value_type

Member Functions

NameDescription
safe_int [constructor]Constructors
operator%= Modulus assignment operator
operator*= Multiplication assignment operator
operator+ Unary plus operator
operator++ Increment operators
operator+= Addition assignment operator
operator- Unary minus operator
operator-- Decrement operators
operator-= Subtraction assignment operator
operator/= Division assignment operator
value
operator T Conversion to T

Data Members

Name
value_

Friends

|===
Name Description
operator<< Stream insertion operator

Template Parameters

Name Description
T the underlying integral type (e.g. int, long, uint32_t)
ErrorPolicy how to react to overflow — default: safe_int_throw_policy on hosted, safe_int_terminate_policy on freestanding