11#include "../macros.hpp"
12#include "concepts.hpp"
16hi_export_module(hikogui.utility.compare);
18hi_export
namespace hi {
inline namespace v1 {
22template<
typename Lhs,
typename Rhs>
25template<std::
unsigned_
integral Lhs, std::
unsigned_
integral Rhs>
27 [[nodiscard]]
constexpr std::strong_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
33template<std::
signed_
integral Lhs, std::
signed_
integral Rhs>
35 [[nodiscard]]
constexpr std::strong_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
41template<std::
floating_po
int Lhs, std::
floating_po
int Rhs>
42struct three_way_comparison<Lhs, Rhs> {
43 [[nodiscard]]
constexpr std::partial_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
49template<std::
signed_
integral Lhs, std::
unsigned_
integral Rhs>
50struct three_way_comparison<Lhs, Rhs> {
51 [[nodiscard]]
constexpr std::strong_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
52 requires(
sizeof(Rhs) <
sizeof(
long long))
54 return lhs <=>
static_cast<long long>(rhs);
57 [[nodiscard]]
constexpr std::strong_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
58 requires(
sizeof(Rhs) ==
sizeof(
long long))
61 return std::strong_ordering::less;
63 return static_cast<unsigned long long>(lhs) <=> rhs;
68template<std::
unsigned_
integral Lhs, std::
signed_
integral Rhs>
69struct three_way_comparison<Lhs, Rhs> {
70 [[nodiscard]]
constexpr std::strong_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
71 requires(
sizeof(Lhs) <
sizeof(
long long))
73 return static_cast<long long>(lhs) <=> rhs;
76 [[nodiscard]]
constexpr std::strong_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
77 requires(
sizeof(Lhs) ==
sizeof(
long long))
80 return std::strong_ordering::greater;
82 return lhs <=>
static_cast<unsigned long long>(rhs);
87template<std::
floating_po
int Lhs, std::
integral Rhs>
88struct three_way_comparison<Lhs, Rhs> {
89 [[nodiscard]]
constexpr std::partial_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
91 if constexpr (
sizeof(Rhs) <
sizeof(
float)) {
93 return lhs <=>
static_cast<float>(rhs);
94 }
else if constexpr (
sizeof(Rhs) <
sizeof(
double)) {
96 return lhs <=>
static_cast<double>(rhs);
98 return lhs <=>
static_cast<long double>(rhs);
103template<std::
integral Lhs, std::
floating_po
int Rhs>
104struct three_way_comparison<Lhs, Rhs> {
105 [[nodiscard]]
constexpr std::partial_ordering operator()(Lhs
const& lhs, Rhs
const& rhs)
const noexcept
107 if constexpr (
sizeof(Lhs) <
sizeof(
float)) {
109 return static_cast<float>(lhs) <=> rhs;
110 }
else if constexpr (
sizeof(Lhs) <
sizeof(
double)) {
112 return static_cast<double>(lhs) <=> rhs;
114 return static_cast<long double>(lhs) <=> rhs;
125template<arithmetic Lhs, arithmetic Rhs>
The HikoGUI namespace.
Definition array_generic.hpp:20
constexpr auto three_way_compare(Lhs const &lhs, Rhs const &rhs) noexcept
Safely compare two arithmetic values to each other.
Definition compare.hpp:126
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A functor to safely compare two arithmetic values.
Definition compare.hpp:23