|
template<typename OutT , typename InT > |
OutT | clamp_to_typerange (InT inVal) |
| Clamps the input value to the legal range for the output type.
|
|
template<typename OutT , typename InT > |
OutT | clamp_to_default (InT inVal, OutT defVal) |
| Adjusts the input value to the default if the input value exceeds the range of the output type.
|
|
template<typename OutT , typename InT , typename FuncT > |
OutT | clamp_notify (InT inVal, FuncT cb) |
| Calls FuncT cb if the input value exceeds the range of the output type.
|
|
template<typename OutT , typename InT > |
OutT | numeric_cast (InT inVal) |
| Tests attempted casts to ensure the input value does not exceed the capacity of the output type.
|
|
template<typename OutT , typename InT > |
constexpr bool | is_int_conversion () |
|
template<typename OutT , typename InT > |
constexpr bool | is_int_u2s () |
|
template<typename OutT , typename InT > |
constexpr bool | is_int_s2u () |
|
template<typename OutT , typename InT > |
constexpr bool | is_int_rangesafe () |
|
template<typename OutT , typename InT > |
bool | is_safe_conversion (InT inVal) |
| Returns true if the given value can be contained by the out type.
|
|
template<typename OutT , typename InT >
OutT openvpn::numeric_util::numeric_cast |
( |
InT |
inVal | ) |
|
Tests attempted casts to ensure the input value does not exceed the capacity of the output type.
If the types are the same, or the range of the output type equals or exceeds the range of the input type we just cast and return the value which should ideally optimize away completely. Otherwise we do appropriate range checks and if those succeed we cast, otherwise the failure exception openvpn::numeric_out_of_range is thrown.
Example:
int64_t s64 = std::numeric_limits<int64_t>::max();
EXPECT_THROW(numeric_cast<int16_t>(s64), numeric_out_of_range);
- Parameters
-
inVal | The value to be converted. |
- Returns
- The safely converted inVal.
- Template Parameters
-
InT | Source (input) type, inferred from 'inVal' |
OutT | Desired result type |
- Exceptions
-
numeric_out_of_range | if the conversion is not safe |
Definition at line 54 of file numeric_cast.hpp.