5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPARE_COMPARE_THREE_WAY_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPARE_COMPARE_THREE_WAY_HPP_
12#include "arene/base/compare/strong_ordering.hpp"
13#include "arene/base/compiler_support/diagnostics.hpp"
14#include "arene/base/constraints/constraints.hpp"
15#include "arene/base/stdlib_choice/declval.hpp"
16#include "arene/base/stdlib_choice/enable_if.hpp"
17#include "arene/base/stdlib_choice/equal_to.hpp"
18#include "arene/base/stdlib_choice/is_integral.hpp"
19#include "arene/base/stdlib_choice/is_pointer.hpp"
20#include "arene/base/stdlib_choice/is_same.hpp"
21#include "arene/base/stdlib_choice/less.hpp"
22#include "arene/base/type_traits/comparison_traits.hpp"
23#include "arene/base/utility/safe_comparisons.hpp"
37template <
typename T,
typename U = T,
typename = constraints<>>
38extern constexpr bool is_three_way_comparable_v =
false;
41template <
typename T,
typename U>
49namespace three_way_compare_detail {
63class compare_three_way {
66 using is_transparent =
void;
79 constraints<std::enable_if_t<std::is_pointer<T>::value>, std::enable_if_t<std::is_pointer<U>::value>> =
nullptr>
80 constexpr auto operator()(T
const& lhs, U
const& rhs)
const noexcept -> strong_ordering {
81 if (std::less<>{}(lhs, rhs)) {
82 return strong_ordering::less;
84 if (std::less<>{}(rhs, lhs)) {
85 return strong_ordering::greater;
87 return strong_ordering::equal;
102 constraints<std::enable_if_t<std::is_integral<T>::value>, std::enable_if_t<std::is_integral<U>::value>> =
nullptr>
103 constexpr auto operator()(T
const& lhs, U
const& rhs)
const noexcept -> strong_ordering {
104 if (::arene::base::cmp_equal(lhs, rhs)) {
105 return strong_ordering::equal;
107 if (::arene::base::cmp_less(lhs, rhs)) {
108 return strong_ordering::less;
110 return strong_ordering::greater;
113 ARENE_IGNORE_START();
114 ARENE_IGNORE_ALL(
"-Wfloat-equal",
"Three-way comparison requires equality check");
127 std::enable_if_t<!is_three_way_comparable_v<T, U>>,
128 std::enable_if_t<!is_three_way_comparable_v<U, T>>,
129 std::enable_if_t<!std::is_pointer<T>::value || !std::is_pointer<U>::value>,
130 std::enable_if_t<!std::is_integral<T>::value || !std::is_integral<U>::value>,
131 std::enable_if_t<base::is_less_than_comparable_v<T, U>>,
132 std::enable_if_t<base::is_equality_comparable_v<T, U>>> =
nullptr>
133 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
134 noexcept(base::is_nothrow_less_than_comparable_v<T, U> && base::is_nothrow_equality_comparable_v<T, U>)
136 if (std::equal_to<>{}(lhs, rhs)) {
137 return strong_ordering::equal;
139 if (std::less<>{}(lhs, rhs)) {
140 return strong_ordering::less;
142 return strong_ordering::greater;
158 std::enable_if_t<!is_three_way_comparable_v<T, U>>,
159 std::enable_if_t<!is_three_way_comparable_v<U, T>>,
160 std::enable_if_t<!std::is_pointer<T>::value || !std::is_pointer<U>::value>,
161 std::enable_if_t<base::is_less_than_comparable_v<T, U>>,
162 std::enable_if_t<!base::is_equality_comparable_v<T, U>>,
163 std::enable_if_t<base::is_less_than_comparable_v<U, T>>> =
nullptr>
164 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
165 noexcept(base::is_nothrow_less_than_comparable_v<T, U> && base::is_nothrow_less_than_comparable_v<U, T>)
167 if (std::less<>{}(lhs, rhs)) {
168 return strong_ordering::less;
170 if (std::less<>{}(rhs, lhs)) {
171 return strong_ordering::greater;
173 return strong_ordering::equal;
182 template <
typename T,
typename U, constraints<std::enable_if_t<is_three_way_comparable_v<T, U>>> =
nullptr>
183 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
184 noexcept(
noexcept(T::three_way_compare(std::declval<T
const&>(), std::declval<U
const&>()))) -> strong_ordering {
185 return T::three_way_compare(lhs, rhs);
198 std::enable_if_t<!is_three_way_comparable_v<T, U>>,
199 std::enable_if_t<is_three_way_comparable_v<U, T>>> =
nullptr>
200 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
201 noexcept(
noexcept(U::three_way_compare(std::declval<U
const&>(), std::declval<T
const&>()))) -> strong_ordering {
202 return opposite_ordering(U::three_way_compare(rhs, lhs));
210using compare_three_way = three_way_compare_detail::compare_three_way;
217template <
typename Lhs,
typename Rhs = Lhs,
typename = constraints<>>
218extern constexpr bool compare_three_way_supported_v =
false;
220template <
typename Lhs,
typename Rhs>
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10