Refactor is_same_signedness.

This commit is contained in:
Paweł Bylica 2016-02-19 19:03:51 +01:00
parent 092a8e53e4
commit abae0bd998

View File

@ -91,12 +91,12 @@ inline constexpr T narrow_cast(U u) noexcept
struct narrowing_error : public std::exception {}; struct narrowing_error : public std::exception {};
template<class T, class U> namespace details
struct is_same_signess
{ {
static const bool value = template<class T, class U>
std::is_signed<T>::value == std::is_signed<U>::value; struct is_same_signedness : public std::integral_constant<bool, std::is_signed<T>::value == std::is_signed<U>::value>
}; {};
}
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value // narrow() : a checked version of narrow_cast() that throws if the cast changed the value
template<class T, class U> template<class T, class U>
@ -105,7 +105,7 @@ inline T narrow(U u)
T t = narrow_cast<T>(u); T t = narrow_cast<T>(u);
if (static_cast<U>(t) != u) if (static_cast<U>(t) != u)
throw narrowing_error(); throw narrowing_error();
if (!is_same_signess<T, U>::value && ((t < T{}) != (u < U{}))) if (!details::is_same_signedness<T, U>::value && ((t < T{}) != (u < U{})))
throw narrowing_error(); throw narrowing_error();
return t; return t;
} }