MCPcopy Create free account
hub / github.com/Tessil/ordered-map / numeric_cast

Function numeric_cast

include/tsl/ordered_hash.h:120–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118
119template <typename T, typename U>
120static 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected