[#mp_units-utility-safe_int-07]
= xref:mp_units.adoc[mp&lowbar;units]::xref:mp_units/utility.adoc[utility]::safe&lowbar;int
:relfileprefix: ../../
:mrdocs:

Wraps an integral type with overflow detection&period;

== Synopsis

Declared in `&lt;mp&hyphen;units&sol;utility&sol;safe&lowbar;int&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    &sol;&ast; implementation-defined &ast;&sol; T,
    xref:mp_units/utility/OverflowPolicy.adoc[OverflowPolicy] EP = xref:mp_units/utility/safe_int_throw_policy.adoc[safe&lowbar;int&lowbar;throw&lowbar;policy]&gt;
class safe&lowbar;int;
----

== Description

This class wraps any integral type and models all requirements for mp&hyphen;units representation types (RealScalar, UnitMagnitudeScalable, etc&period;)&period; Every arithmetic operation checks for overflow and delegates to the ErrorPolicy&colon;&colon;on&lowbar;overflow() handler on detection&period;

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:mp_units/utility/safe_int-07/error_policy.adoc[`error&lowbar;policy`] 
| The `ErrorPolicy` used to react to overflow&period;
| xref:mp_units/utility/safe_int-07/value_type.adoc[`value&lowbar;type`] 
| The underlying integral type `T`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:mp_units/utility/safe_int-07/2constructor-03.adoc[`safe&lowbar;int`]         [.small]#[constructor]#
| Constructors
| xref:mp_units/utility/safe_int-07/operator_mod_eq.adoc[`operator%&equals;`] 
| Replaces the wrapped value with its remainder after division by `rhs,` reacting to `ErrorPolicy` on division by zero&period;
| xref:mp_units/utility/safe_int-07/operator_star_eq.adoc[`operator&ast;&equals;`] 
| Multiplies the wrapped value by `rhs,` reacting to `ErrorPolicy` on overflow&period;
| xref:mp_units/utility/safe_int-07/operator_plus.adoc[`operator&plus;`] 
| Returns a copy of the wrapped value, promoted as `&plus;value&lowbar;` would promote `T`&period;
| xref:mp_units/utility/safe_int-07/operator_inc-0ea.adoc[`operator&plus;&plus;`] 
| Increment operators
| xref:mp_units/utility/safe_int-07/operator_plus_eq.adoc[`operator&plus;&equals;`] 
| Adds `rhs` to the wrapped value, reacting to `ErrorPolicy` on overflow&period;
| xref:mp_units/utility/safe_int-07/operator_minus.adoc[`operator&hyphen;`] 
| Returns the negation of the wrapped value, reacting to `ErrorPolicy` on overflow&period;
| xref:mp_units/utility/safe_int-07/operator_dec-0f6.adoc[`operator&hyphen;&hyphen;`] 
| Decrement operators
| xref:mp_units/utility/safe_int-07/operator_minus_eq.adoc[`operator&hyphen;&equals;`] 
| Subtracts `rhs` from the wrapped value, reacting to `ErrorPolicy` on overflow&period;
| xref:mp_units/utility/safe_int-07/operator_slash_eq.adoc[`operator&sol;&equals;`] 
| Divides the wrapped value by `rhs,` reacting to `ErrorPolicy` on overflow or division by zero&period;
| xref:mp_units/utility/safe_int-07/value.adoc[`value`] 
| Returns the wrapped value&period;
| xref:mp_units/utility/safe_int-07/2conversion.adoc[`operator T`] 
| Converts to the wrapped value&period;
|===


== Data Members

[cols="1,4"]
|===
| Name| Description
| xref:mp_units/utility/safe_int-07/value_.adoc[`value&lowbar;`] 
| The wrapped value&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:mp_units/utility/safe_int-0b.adoc[`safe&lowbar;int&lt;T&gt;`] 
| Deduces `safe&lowbar;int&lt;T&gt;` (with the default `ErrorPolicy`) from an integral value&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:mp_units/utility/operator_lshift.adoc[mp&lowbar;units::utility::operator&lt;&lt;]`
| Streams a safe&lowbar;int&apos;s wrapped value to an output stream
| `xref:mp_units/utility/operator_3way-09a.adoc[mp&lowbar;units::utility::operator&lt;&equals;&gt;]`
| Compares a safe&lowbar;int with a constrained value
| `xref:mp_units/utility/operator_eq-07.adoc[mp&lowbar;units::utility::operator&equals;&equals;]`
| Checks whether a safe&lowbar;int and a constrained value are equal
| `xref:mp_units/utility/operator_slash-082.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a safe&lowbar;int by a non&hyphen;integral constrained value
| `xref:mp_units/utility/operator_slash-04.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a non&hyphen;integral constrained value by a safe&lowbar;int
| `xref:mp_units/utility/operator_star-0e4.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a safe&lowbar;int by a non&hyphen;integral constrained value
| `xref:mp_units/utility/operator_star-0e8.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a non&hyphen;integral constrained value by a safe&lowbar;int
| `xref:mp_units/utility/operator_minus-07.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a non&hyphen;integral constrained value from a safe&lowbar;int
| `xref:mp_units/utility/operator_minus-01.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a safe&lowbar;int from a non&hyphen;integral constrained value
| `xref:mp_units/utility/operator_plus-0fe8.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a non&hyphen;integral constrained value to a safe&lowbar;int
| `xref:mp_units/utility/operator_plus-06b.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a safe&lowbar;int to a non&hyphen;integral constrained value
| `xref:mp_units/utility/operator_mod-06.adoc[mp&lowbar;units::utility::operator%]`
| Computes the remainder of dividing a safe&lowbar;int by a constrained value
| `xref:mp_units/utility/operator_mod-0e.adoc[mp&lowbar;units::utility::operator%]`
| Computes the remainder of dividing a constrained value by a safe&lowbar;int
| `xref:mp_units/utility/operator_slash-09.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a safe&lowbar;int by a constrained value
| `xref:mp_units/utility/operator_slash-08b.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a constrained value by a safe&lowbar;int
| `xref:mp_units/utility/operator_star-049.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a safe&lowbar;int by a constrained value
| `xref:mp_units/utility/operator_star-0b.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a constrained value by a safe&lowbar;int
| `xref:mp_units/utility/operator_minus-0b.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a constrained value from a safe&lowbar;int
| `xref:mp_units/utility/operator_minus-05.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a safe&lowbar;int from a constrained value
| `xref:mp_units/utility/operator_plus-06f.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a safe&lowbar;int to a constrained value
| `xref:mp_units/utility/operator_plus-02.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a constrained value to a safe&lowbar;int
| `xref:mp_units/utility/operator_3way-021.adoc[mp&lowbar;units::utility::operator&lt;&equals;&gt;]`
| Compares a `safe&lowbar;int` with a floating&hyphen;point value&period;
| `xref:mp_units/utility/operator_eq-0e.adoc[mp&lowbar;units::utility::operator&equals;&equals;]`
| Checks whether a `safe&lowbar;int` equals a floating&hyphen;point value&period;
| `xref:mp_units/utility/operator_slash-05.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a floating&hyphen;point value by a `safe&lowbar;int`&period;
| `xref:mp_units/utility/operator_slash-07.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a `safe&lowbar;int` by a floating&hyphen;point value&period;
| `xref:mp_units/utility/operator_star-01.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a floating&hyphen;point value by a `safe&lowbar;int`&period;
| `xref:mp_units/utility/operator_star-0a.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a `safe&lowbar;int` by a floating&hyphen;point value&period;
| `xref:mp_units/utility/operator_minus-03.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a `safe&lowbar;int` from a floating&hyphen;point value&period;
| `xref:mp_units/utility/operator_minus-04.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a floating&hyphen;point value from a `safe&lowbar;int`&period;
| `xref:mp_units/utility/operator_plus-0fec.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a `safe&lowbar;int` to a floating&hyphen;point value&period;
| `xref:mp_units/utility/operator_plus-0d.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a floating&hyphen;point value to a `safe&lowbar;int`&period;
| `xref:mp_units/utility/operator_3way-097.adoc[mp&lowbar;units::utility::operator&lt;&equals;&gt;]`
| Compares a `safe&lowbar;int` with an integral scalar, comparing safely across signedness&period;
| `xref:mp_units/utility/operator_eq-01.adoc[mp&lowbar;units::utility::operator&equals;&equals;]`
| Checks whether a `safe&lowbar;int` equals an integral scalar, comparing safely across signedness&period;
| `xref:mp_units/utility/operator_mod-09.adoc[mp&lowbar;units::utility::operator%]`
| Computes the remainder of dividing an integral scalar by a `safe&lowbar;int`&period;
| `xref:mp_units/utility/operator_mod-04.adoc[mp&lowbar;units::utility::operator%]`
| Computes the remainder of dividing a `safe&lowbar;int` by an integral scalar&period;
| `xref:mp_units/utility/operator_slash-02.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides an integral scalar by a `safe&lowbar;int`, checking for overflow&period;
| `xref:mp_units/utility/operator_slash-0d.adoc[mp&lowbar;units::utility::operator&sol;]`
| Divides a `safe&lowbar;int` by an integral scalar, checking for overflow&period;
| `xref:mp_units/utility/operator_star-02.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies an integral scalar by a `safe&lowbar;int`, checking for overflow&period;
| `xref:mp_units/utility/operator_star-04e.adoc[mp&lowbar;units::utility::operator&ast;]`
| Multiplies a `safe&lowbar;int` by an integral scalar, checking for overflow&period;
| `xref:mp_units/utility/operator_minus-02.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts a `safe&lowbar;int` from an integral scalar, checking for overflow&period;
| `xref:mp_units/utility/operator_minus-0de.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Subtracts an integral scalar from a `safe&lowbar;int`, checking for overflow&period;
| `xref:mp_units/utility/operator_plus-0e9.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds a `safe&lowbar;int` to an integral scalar, checking for overflow&period;
| `xref:mp_units/utility/operator_plus-0e0.adoc[mp&lowbar;units::utility::operator&plus;]`
| Adds an integral scalar to a `safe&lowbar;int`, checking for overflow&period;
| `xref:mp_units/utility/operator_3way-06.adoc[mp&lowbar;units::utility::operator&lt;&equals;&gt;]`
| Compares two `safe&lowbar;int` values by their wrapped underlying values&period;
| `xref:mp_units/utility/operator_eq-0b.adoc[mp&lowbar;units::utility::operator&equals;&equals;]`
| Checks whether two `safe&lowbar;int` values wrap equal underlying values&period;
| `xref:mp_units/utility/operator_mod-0c.adoc[mp&lowbar;units::utility::operator%]`
| Computes the remainder of dividing `lhs` by `rhs&period;`
| `xref:mp_units/utility/operator_slash-0e.adoc[mp&lowbar;units::utility::operator&sol;]`
| Computes the quotient of dividing `lhs` by `rhs&period;`
| `xref:mp_units/utility/operator_star-0c.adoc[mp&lowbar;units::utility::operator&ast;]`
| Computes the product of `lhs` and `rhs&period;`
| `xref:mp_units/utility/operator_minus-09.adoc[mp&lowbar;units::utility::operator&hyphen;]`
| Computes the difference of `lhs` and `rhs&period;`
| `xref:mp_units/utility/operator_plus-01.adoc[mp&lowbar;units::utility::operator&plus;]`
| Computes the sum of `lhs` and `rhs&period;`
|===

== Template Parameters

[cols="1,4"]
|===
| Name| Description
| *T*
| the underlying integral type (e&period;g&period; int, long, uint32&lowbar;t)
| *ErrorPolicy*
| how to react to overflow — default&colon; safe&lowbar;int&lowbar;throw&lowbar;policy on hosted, safe&lowbar;int&lowbar;terminate&lowbar;policy on freestanding
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
