[ox/std] Fix implementation of std cmp functions
All checks were successful
Build / build (push) Successful in 1m12s

This commit is contained in:
2025-05-23 00:49:47 -05:00
parent a40198ab8d
commit 312097a799

View File

@ -32,9 +32,9 @@ constexpr bool cmp_equal(T const t, U const u) noexcept {
if constexpr(ox::is_signed_v<T> == ox::is_signed_v<U>) {
return t == u;
} else if constexpr(ox::is_signed_v<T>) {
return ox::Signed<T>{t} == u;
return t >= 0 && static_cast<ox::Unsigned<T>>(t) == u;
} else {
return t == ox::Signed<U>{u};
return u >= 0 && t == static_cast<ox::Unsigned<U>>(u);
}
}
@ -43,9 +43,9 @@ constexpr bool cmp_less(T const t, U const u) noexcept {
if constexpr(ox::is_signed_v<T> == ox::is_signed_v<U>) {
return t < u;
} else if constexpr(ox::is_signed_v<T>) {
return ox::Signed<T>{t} < u;
return t < 0 || static_cast<ox::Unsigned<T>>(t) < u;
} else {
return t < ox::Signed<U>{u};
return u >= 0 && t < static_cast<ox::Unsigned<U>>(u);
}
}
@ -69,6 +69,13 @@ constexpr bool cmp_greater_equal(T const t, U const u) noexcept {
return !std::cmp_less(t, u);
}
static_assert(cmp_less(-1, 5u));
static_assert(!cmp_less(5u, -1));
static_assert(cmp_equal(5u, 5));
static_assert(cmp_equal(5, 5u));
static_assert(!cmp_equal(-5, 5u));
static_assert(!cmp_equal(4u, 5u));
}
#endif