From 4c03e8a8cd1e7e6ba188fcf3ee3b84d451771611 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 23 May 2025 00:49:47 -0500 Subject: [PATCH] [ox/std] Fix implementation of std cmp functions (synced from 312097a7991194ce36e7c2e357e7e3a51d916767) --- src/ox/std/utility.hpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ox/std/utility.hpp b/src/ox/std/utility.hpp index f1e553018..846217625 100644 --- a/src/ox/std/utility.hpp +++ b/src/ox/std/utility.hpp @@ -32,9 +32,9 @@ constexpr bool cmp_equal(T const t, U const u) noexcept { if constexpr(ox::is_signed_v == ox::is_signed_v) { return t == u; } else if constexpr(ox::is_signed_v) { - return ox::Signed{t} == u; + return t >= 0 && static_cast>(t) == u; } else { - return t == ox::Signed{u}; + return u >= 0 && t == static_cast>(u); } } @@ -43,9 +43,9 @@ constexpr bool cmp_less(T const t, U const u) noexcept { if constexpr(ox::is_signed_v == ox::is_signed_v) { return t < u; } else if constexpr(ox::is_signed_v) { - return ox::Signed{t} < u; + return t < 0 || static_cast>(t) < u; } else { - return t < ox::Signed{u}; + return u >= 0 && t < static_cast>(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