In narrow refactor !is_same_signedness to is_different_signedness

This commit is contained in:
Robert Andrzejuk
2020-04-29 20:39:44 +02:00
committed by GitHub
parent 1e5f44d3ea
commit 84847041ee

View File

@@ -109,12 +109,12 @@ constexpr
#endif #endif
T narrow(U u) noexcept(false) T narrow(U u) noexcept(false)
{ {
constexpr const bool is_same_signedness = std::is_signed<T>::value == std::is_signed<U>::value; constexpr const bool is_different_signedness = (std::is_signed<T>::value != std::is_signed<U>::value);
const T t = narrow_cast<T>(u); const T t = narrow_cast<T>(u);
if (static_cast<U>(t) != u if (static_cast<U>(t) != u
|| (!is_same_signedness || (is_different_signedness
&& ((t < T{}) != (u < U{})))) && ((t < T{}) != (u < U{}))))
{ {
throw narrowing_error{}; throw narrowing_error{};