mirror of
https://github.com/microsoft/GSL.git
synced 2025-03-26 14:58:31 -04:00
In narrow
refactor !is_same_signedness
to is_different_signedness
This commit is contained in:
parent
1e5f44d3ea
commit
84847041ee
@ -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{};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user