[ox/std] Add comparison functions
All checks were successful
Build / build (push) Successful in 1m24s

This commit is contained in:
Gary Talent 2025-02-18 21:46:41 -06:00
parent fefb876fe7
commit 998066d377

View File

@ -27,6 +27,48 @@ constexpr void swap(T &a, T &b) noexcept {
b = std::move(temp);
}
template<typename T, typename U>
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;
} else {
return t == ox::Signed<U>{u};
}
}
template<typename T, typename U>
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;
} else {
return t < ox::Signed<U>{u};
}
}
template<typename T, typename U>
constexpr bool cmp_not_equal(T const t, U const u) noexcept {
return !std::cmp_equal(t, u);
}
template<typename T, typename U>
constexpr bool cmp_greater(T const t, U const u) noexcept {
return std::cmp_less(u, t);
}
template<typename T, typename U>
constexpr bool cmp_less_equal(T const t, U const u) noexcept {
return !std::cmp_less(u, t);
}
template<typename T, typename U>
constexpr bool cmp_greater_equal(T const t, U const u) noexcept {
return !std::cmp_less(t, u);
}
}
#endif