forked from mpusz/mp-units
Use in_range
for integer case
This commit is contained in:
@@ -196,8 +196,7 @@ constexpr To checked_static_cast(From x) {
|
|||||||
// This function should only ever be called at compile time. The purpose of these exceptions is
|
// This function should only ever be called at compile time. The purpose of these exceptions is
|
||||||
// to produce compiler errors, because we cannot `static_assert` on function arguments.
|
// to produce compiler errors, because we cannot `static_assert` on function arguments.
|
||||||
if constexpr (std::is_integral_v<To>) {
|
if constexpr (std::is_integral_v<To>) {
|
||||||
if (std::cmp_less(x, std::numeric_limits<To>::min()) ||
|
if (!std::in_range<To>(x)) {
|
||||||
std::cmp_greater(x, std::numeric_limits<To>::max())) {
|
|
||||||
throw std::invalid_argument{"Cannot represent magnitude in this type"};
|
throw std::invalid_argument{"Cannot represent magnitude in this type"};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user