![]() |
Home | Libraries | People | FAQ | More |
This type holds a signed 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.
In addition
| Symbol | Description |
|---|---|
MIN, MAX |
Minimum and maximum signed values that the safe_signed_range can represent. |
PP |
A type which specifes the result type of an expression using safe types. |
EP |
A type containing members which are called when a correct result cannot be returned |
| Parameter | Requirements | Description |
|---|---|---|
MIN |
must be an integer literal | The minimum integer value that this type may hold |
MAX |
must be a negative literal | The maximum integer value that this type may hold |
| MIN <= MAX | must be a valid closed range | |
PP |
PromotionPolicy<PP> | Default value is boost::numeric::native |
EP |
Exception Policy<EP> | Default value is boost::throw_exception |
Implements all expressions and only those expressions defined by the SafeNumeric type requirements. This, the result type of such an expression will be another safe type. The actual type of the result of such an expression will depend upon the specific promotion policy template parameter.
#include <safe/numeric/safe_range.hpp>
void f(){
boost::numeric::safe_signed_range<-7, 24> i;
// since the range is included in [-128,127], the underlying type of i
// will be a char.
i = -41; // throws out_of_range exception
i = 9; // ok
i = -1; // ok
i *= 9; // throws out_of_range exception
std::int8_t j = 4;
auto k = i + j;
// These types use default promotion policy so standard C++ type promotion rules
// will be used in evaluating expressions. C++ type promotion rules mandate
// that the result of k = i + j when both are signed char types, will be another
// signed char type.
}