| 118 | |
| 119 | template <typename T, typename U> |
| 120 | static T numeric_cast(U value, |
| 121 | const char* error_message = "numeric_cast() failed.") { |
| 122 | T ret = static_cast<T>(value); |
| 123 | if (static_cast<U>(ret) != value) { |
| 124 | TSL_OH_THROW_OR_TERMINATE(std::runtime_error, error_message); |
| 125 | } |
| 126 | |
| 127 | const bool is_same_signedness = |
| 128 | (std::is_unsigned<T>::value && std::is_unsigned<U>::value) || |
| 129 | (std::is_signed<T>::value && std::is_signed<U>::value); |
| 130 | if (!is_same_signedness && (ret < T{}) != (value < U{})) { |
| 131 | TSL_OH_THROW_OR_TERMINATE(std::runtime_error, error_message); |
| 132 | } |
| 133 | |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Fixed size type used to represent size_type values on serialization. Need to |
nothing calls this directly
no outgoing calls
no test coverage detected