1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-10 23:44:29 +00:00

clean-up mixed_sign_less

This commit is contained in:
neargye 2019-10-14 17:29:35 +05:00
parent 1c04e115de
commit 6c9c498faa

View file

@ -145,15 +145,15 @@ template <typename L, typename R>
constexpr bool mixed_sign_less(L lhs, R rhs) noexcept { constexpr bool mixed_sign_less(L lhs, R rhs) noexcept {
static_assert(std::is_integral_v<L> && std::is_integral_v<R>, "magic_enum::detail::mixed_sign_less requires integral type."); static_assert(std::is_integral_v<L> && std::is_integral_v<R>, "magic_enum::detail::mixed_sign_less requires integral type.");
if constexpr(std::is_signed_v<L> == std::is_signed_v<R>) { if constexpr (std::is_signed_v<L> && std::is_unsigned_v<R>) {
// If same signedness (both signed or both unsigned).
return lhs < rhs;
} else if constexpr(std::is_signed_v<L>) {
// If 'left' is negative, then result is 'true', otherwise cast & compare. // If 'left' is negative, then result is 'true', otherwise cast & compare.
return lhs < 0 || static_cast<std::make_unsigned_t<L>>(lhs) < rhs; return lhs < 0 || static_cast<std::make_unsigned_t<L>>(lhs) < rhs;
} else { // std::is_signed_v<R> } else if constexpr (std::is_unsigned_v<L> && std::is_signed_v<R>) {
// If 'right' is negative, then result is 'false', otherwise cast & compare. // If 'right' is negative, then result is 'false', otherwise cast & compare.
return rhs >= 0 && lhs < static_cast<std::make_unsigned_t<R>>(rhs); return rhs >= 0 && lhs < static_cast<std::make_unsigned_t<R>>(rhs);
} else {
// If same signedness (both signed or both unsigned).
return lhs < rhs;
} }
} }