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_
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"
37template <
typename T,
typename U = T,
typename = constra
ints<>>
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;
114 ARENE_IGNORE_ALL(
"-Wfloat-equal",
"Three-way comparison requires equality check");
134 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
137 if (std::equal_to<>{}(lhs, rhs)) {
138 return strong_ordering::equal;
140 if (std::less<>{}(lhs, rhs)) {
141 return strong_ordering::less;
143 return strong_ordering::greater;
166 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
169 if (std::less<>{}(lhs, rhs)) {
170 return strong_ordering::less;
172 if (std::less<>{}(rhs, lhs)) {
173 return strong_ordering::greater;
175 return strong_ordering::equal;
184 template <
typename T,
typename U, constra
ints<std::enable_if_t<is_three_way_comparable_v<T, U>>> =
nullptr>
185 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
187 return T::three_way_compare(lhs, rhs);
203 constexpr auto operator()(T
const& lhs, U
const& rhs)
const
221template <
typename Lhs,
typename Rhs = Lhs,
typename = constra
ints<>>
224template <
typename Lhs,
typename Rhs>
static constexpr value_type value
Definition integral_constant.hpp:34
Provides macros used to disable and enable compiler specific diagnostics using the _Pragma operator.
#define ARENE_IGNORE_END()
Ends a region of a suppressed diagnostic.
Definition diagnostics.hpp:136
#define ARENE_IGNORE_START()
Begins a region of a suppressed diagnostic.
Definition diagnostics.hpp:131
#define ARENE_IGNORE_ALL(s, comment)
Pushes an ignore for a diagnostic into the compiler for any compiler.
Definition diagnostics.hpp:122
Definition accumulate.hpp:37
constexpr bool compare_three_way_supported_v
Boolean constant indicating if instances of Lhs and Rhs can be compared using compare_three_way.
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
three_way_compare_detail::compare_three_way compare_three_way
Function object that does a three-way comparison between operands, equivalent to std::compare_three_w...
Definition compare_three_way.hpp:214
constexpr auto opposite_ordering(strong_ordering const ordering) noexcept -> strong_ordering
Return the opposite ordering for a strong_ordering three-way-comparison result.
Definition strong_ordering.hpp:209
constexpr bool is_nothrow_equality_comparable_v
constexpr bool is_three_way_comparable_v
Type trait to check if an instance of type T can be compared to an instance of type U with a static t...
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
constexpr bool is_nothrow_less_than_comparable_v
Definition accumulate.hpp:36
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
Provides backports of the safe integer comparison functions from C++20.