![]() |
Home | Libraries | People | FAQ | More |
This type holds a integer in the range [MIN, MAX]. It will throw a
std::out_of_range exception for operation which would result
in assigning an integer value outside of this range.
| Symbol | Description |
|---|---|
T, U, V |
Types which model the Numeric concept |
| t, u, v | objects of types T |
| ssr | object of type safe_signed_range |
| ssr(t) | some safe range with value t |
| S | some safe type |
| Parameter | Requirements | Description |
|---|---|---|
MIN |
must be an integer literal | The minimum integer value that this type may hold |
MAX |
must be an integer literal | The maximum integer value that this type may hold |
|
MIN < MAX |
The usage of this type in an arithmetic expression will result in another type fulfilling the Numeric concept.
Operations on safe_signed_range will result in the same
| Expression | Result Type | Description |
|---|---|---|
ssr op u |
S(ssr(t op u)) | op is any valid binary operator for type T |
t op su |
S(ssr(t op u)) | op is any valid binary operator for type T |
ssr op su |
S(ssr(t op u)) | op is any valid binary operator for type T |
safe_signed_range(MIN, MAX) |
safe<T> | construct a instance of safe<T> from t |
#include <safe/numeric/safe_range.hpp>
void f(){
boost::numeric::safe_signed_range<7, 24> i;
i = 0; // error
i = 9; // ok
i *= 9; // throws overflow exception
std::int8_t j = 4;
auto k = i + j;
// since i can vary between 7 and 24 and j can vary between 0 and 255
// the smallest unsigned integer which can hold the result std::int16_t
// j will be of type std::int16_t
}