5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPARE_OPERATORS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPARE_OPERATORS_HPP_
20#include "arene/base/stdlib_choice/declval.hpp"
21#include "arene/base/stdlib_choice/enable_if.hpp"
22#include "arene/base/stdlib_choice/is_base_of.hpp"
23#include "arene/base/stdlib_choice/is_class.hpp"
24#include "arene/base/stdlib_choice/is_same.hpp"
35namespace operators_detail {
40template <
typename LhsType,
typename RhsType>
41class inequality_operator_mixin {
49 ARENE_NODISCARD friend constexpr auto operator!=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
57 constexpr inequality_operator_mixin() noexcept = default;
59 ~inequality_operator_mixin() noexcept = default;
62 constexpr inequality_operator_mixin(inequality_operator_mixin const& other) noexcept = default;
65 constexpr inequality_operator_mixin(inequality_operator_mixin&& other) noexcept = default;
68 constexpr auto operator=(inequality_operator_mixin const& other) & noexcept -> inequality_operator_mixin& = default;
71 constexpr auto operator=(inequality_operator_mixin&& other) & noexcept -> inequality_operator_mixin& = default;
95template <typename Derived, typename Other = Derived>
97 : operators_detail::inequality_operator_mixin<Derived, Other>
98 , operators_detail::inequality_operator_mixin<Other, Derived> {
118 ) noexcept = default;
122 ) noexcept = default;
135template <typename Derived>
137 : operators_detail::inequality_operator_mixin<Derived, Derived> {
146 )
noexcept =
default;
150 )
noexcept =
default;
162namespace operators_detail {
167template <
typename LhsType,
typename RhsType>
168class ordering_operators_from_three_way_mixin {
174 ARENE_NODISCARD friend constexpr auto operator<(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
179 "LhsType class must provide three_way_compare function that "
180 "returns strong_ordering"
182 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
184 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::less;
193 ARENE_NODISCARD friend constexpr auto operator>(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
197 std::is_same<
decltype(LhsType::three_way_compare(lhs, rhs)), strong_ordering>::value,
198 "LhsType class must provide three_way_compare function that "
199 "returns strong_ordering"
201 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
203 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::greater;
213 ARENE_NODISCARD friend constexpr auto operator<=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
217 std::is_same<
decltype(LhsType::three_way_compare(lhs, rhs)), strong_ordering>::value,
218 "LhsType class must provide three_way_compare function that "
219 "returns strong_ordering"
221 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
223 auto const cmp_res = LhsType::three_way_compare(lhs, rhs);
224 return cmp_res == strong_ordering::less || cmp_res == strong_ordering::equal;
237 ARENE_NODISCARD friend constexpr auto operator>=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
241 std::is_same<
decltype(LhsType::three_way_compare(lhs, rhs)), strong_ordering>::value,
242 "LhsType class must provide three_way_compare function that "
243 "returns strong_ordering"
245 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
247 auto const cmp_res = LhsType::three_way_compare(lhs, rhs);
248 return cmp_res == strong_ordering::greater || cmp_res == strong_ordering::equal;
254 constexpr ordering_operators_from_three_way_mixin() noexcept = default;
256 ~ordering_operators_from_three_way_mixin() noexcept = default;
259 constexpr ordering_operators_from_three_way_mixin(ordering_operators_from_three_way_mixin const& other
260 ) noexcept = default;
263 constexpr ordering_operators_from_three_way_mixin(ordering_operators_from_three_way_mixin&& other) noexcept = default;
266 constexpr auto operator=(ordering_operators_from_three_way_mixin const& other) & noexcept
267 -> ordering_operators_from_three_way_mixin& = default;
270 constexpr auto operator=(ordering_operators_from_three_way_mixin&& other) & noexcept
271 -> ordering_operators_from_three_way_mixin& = default;
302template <typename Derived, typename Other = Derived>
306 , operators_detail::ordering_operators_from_three_way_mixin<Derived, Other> {
359 ) noexcept = default;
364 ) noexcept = default;
377ARENE_IGNORE_ALL(
"-Wdeprecated-declarations",
"We still want to specialize the deprecated classes");
380template <typename Derived>
383 , operators_detail::ordering_operators_from_three_way_mixin<Derived, Derived> {
394 )
noexcept =
default;
399 )
noexcept =
default;
414 "-Wdeprecated-declarations",
415 "We still want to use the deprecated class in this other deprecated class"
439template <
typename Derived,
typename Other = Derived>
453 "Derived class must provide three_way_compare function that "
454 "returns strong_ordering"
456 static_assert(
noexcept(Derived::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
458 return Derived::three_way_compare(lhs, rhs) == strong_ordering::equal;
470 ) noexcept = default;
474 ) noexcept = default;
486namespace operators_detail {
491template <
typename LhsType,
typename RhsType>
492class ordering_operators_from_less_than_mixin {
500 return static_cast<bool>(rhs < lhs);
513 return !
static_cast<bool>(rhs < lhs);
526 return !
static_cast<bool>(lhs < rhs);
532 constexpr ordering_operators_from_less_than_mixin()
noexcept =
default;
534 ~ordering_operators_from_less_than_mixin()
noexcept =
default;
537 constexpr ordering_operators_from_less_than_mixin(ordering_operators_from_less_than_mixin
const& other
538 )
noexcept =
default;
541 constexpr ordering_operators_from_less_than_mixin(ordering_operators_from_less_than_mixin&& other)
noexcept =
default;
544 constexpr auto operator=(ordering_operators_from_less_than_mixin
const& other) &
noexcept
545 -> ordering_operators_from_less_than_mixin& =
default;
548 constexpr auto operator=(ordering_operators_from_less_than_mixin&& other) &
noexcept
549 -> ordering_operators_from_less_than_mixin& =
default;
586template <
typename Derived,
typename Other = Derived>
588 : operators_detail::ordering_operators_from_less_than_mixin<Derived, Other>
589 , operators_detail::ordering_operators_from_less_than_mixin<Other, Derived>
601 ) noexcept = default;
605 ) noexcept = default;
618template <typename Derived>
620 : operators_detail::ordering_operators_from_less_than_mixin<Derived, Derived>
631 )
noexcept =
default;
635 )
noexcept =
default;
676template <
typename Derived,
typename Other = Derived>
688 return !
static_cast<bool>(lhs < rhs) && !static_cast<bool>(rhs < lhs);
709template <
typename T,
typename U = T,
typename = constra
ints<>>
710extern constexpr bool has_fast_inequality_check_v =
false;
713template <
typename T,
typename U>
714extern constexpr bool has_fast_inequality_check_v<
719 inequality_heuristic>::value>>> =
true;
721template <
typename Derived>
722class generic_ordering_from_three_way_compare;
724template <
typename Derived>
725class generic_ordering_from_three_way_compare_and_equals;
727namespace operators_detail {
731template <
typename Type,
typename = constra
ints<>>
732extern constexpr bool uses_generic_three_way_v =
false;
736template <
typename Type>
737extern constexpr bool uses_generic_three_way_v<Type, constraints<std::enable_if_t<std::is_class<Type>::value>>> =
742template <
typename Type,
typename = constra
ints<>>
743extern constexpr bool uses_generic_three_way_and_equals_v =
false;
747template <
typename Type>
749 uses_generic_three_way_and_equals_v<Type, constraints<std::enable_if_t<std::is_class<Type>::value>>> =
755template <
typename Self,
typename Other>
756extern constexpr bool eligible_for_reversed_equals_with_v =
765class generic_ordering_tag {
779 ARENE_NODISCARD friend constexpr auto operator<(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
782 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
784 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::less;
802 ARENE_NODISCARD friend constexpr auto operator<(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
805 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
807 return RhsType::three_way_compare(rhs, lhs) == strong_ordering::greater;
824 ARENE_NODISCARD friend constexpr auto operator>(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
827 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
829 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::greater;
847 ARENE_NODISCARD friend constexpr auto operator>(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
850 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
852 return RhsType::three_way_compare(rhs, lhs) == strong_ordering::less;
869 ARENE_NODISCARD friend constexpr auto operator<=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
872 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
874 return LhsType::three_way_compare(lhs, rhs) != strong_ordering::greater;
892 ARENE_NODISCARD friend constexpr auto operator<=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
895 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
897 return RhsType::three_way_compare(rhs, lhs) != strong_ordering::less;
914 ARENE_NODISCARD friend constexpr auto operator>=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
917 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
919 return LhsType::three_way_compare(lhs, rhs) != strong_ordering::less;
937 ARENE_NODISCARD friend constexpr auto operator>=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
940 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
942 return RhsType::three_way_compare(rhs, lhs) != strong_ordering::greater;
960 ARENE_NODISCARD friend constexpr auto operator==(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
963 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
965 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::equal;
983 ARENE_NODISCARD friend constexpr auto operator==(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
986 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
987 static_assert(
noexcept(LhsType::fast_inequality_check(lhs, rhs)),
"fast_inequality_check must be noexcept");
989 return (LhsType::fast_inequality_check(lhs, rhs) == inequality_heuristic::may_be_equal_or_not_equal) &&
990 (LhsType::three_way_compare(lhs, rhs) == strong_ordering::equal);
1008 ARENE_NODISCARD friend constexpr auto operator==(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1026 ARENE_NODISCARD friend constexpr auto operator!=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1027 return !(lhs == rhs);
1045 ARENE_NODISCARD friend constexpr auto operator!=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1046 return !(lhs == rhs);
1052 constexpr generic_ordering_tag() noexcept = default;
1054 ~generic_ordering_tag() noexcept = default;
1057 constexpr generic_ordering_tag(generic_ordering_tag const& other) noexcept = default;
1060 constexpr generic_ordering_tag(generic_ordering_tag&& other) noexcept = default;
1063 constexpr auto operator=(generic_ordering_tag const& other) & noexcept -> generic_ordering_tag& = default;
1066 constexpr auto operator=(generic_ordering_tag&& other) & noexcept -> generic_ordering_tag& = default;
1074class generic_ordering_and_equals_tag {
1088 ARENE_NODISCARD friend constexpr auto operator<(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1091 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
1093 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::less;
1111 ARENE_NODISCARD friend constexpr auto operator<(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1114 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
1116 return RhsType::three_way_compare(rhs, lhs) == strong_ordering::greater;
1133 ARENE_NODISCARD friend constexpr auto operator>(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1136 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
1138 return LhsType::three_way_compare(lhs, rhs) == strong_ordering::greater;
1156 ARENE_NODISCARD friend constexpr auto operator>(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1159 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
1161 return RhsType::three_way_compare(rhs, lhs) == strong_ordering::less;
1178 ARENE_NODISCARD friend constexpr auto operator<=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1181 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
1183 return LhsType::three_way_compare(lhs, rhs) != strong_ordering::greater;
1201 ARENE_NODISCARD friend constexpr auto operator<=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1204 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
1206 return RhsType::three_way_compare(rhs, lhs) != strong_ordering::less;
1223 ARENE_NODISCARD friend constexpr auto operator>=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1226 static_assert(
noexcept(LhsType::three_way_compare(lhs, rhs)),
"three_way_compare must be noexcept");
1228 return LhsType::three_way_compare(lhs, rhs) != strong_ordering::less;
1246 ARENE_NODISCARD friend constexpr auto operator>=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1249 static_assert(
noexcept(RhsType::three_way_compare(rhs, lhs)),
"three_way_compare must be noexcept");
1251 return RhsType::three_way_compare(rhs, lhs) != strong_ordering::greater;
1268 ARENE_NODISCARD friend constexpr auto operator==(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1286 ARENE_NODISCARD friend constexpr auto operator!=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1287 return !(lhs == rhs);
1304 ARENE_NODISCARD friend constexpr auto operator!=(LhsType
const& lhs, RhsType
const& rhs)
noexcept ->
bool {
1305 return !(lhs == rhs);
1311 constexpr generic_ordering_and_equals_tag() noexcept = default;
1313 ~generic_ordering_and_equals_tag() noexcept = default;
1316 constexpr generic_ordering_and_equals_tag(generic_ordering_and_equals_tag const& other) noexcept = default;
1319 constexpr generic_ordering_and_equals_tag(generic_ordering_and_equals_tag&& other) noexcept = default;
1322 constexpr auto operator=(generic_ordering_and_equals_tag const& other) & noexcept
1323 -> generic_ordering_and_equals_tag& = default;
1326 constexpr auto operator=(generic_ordering_and_equals_tag&& other) & noexcept
1327 -> generic_ordering_and_equals_tag& = default;
1357template <typename Derived>
1368 ) noexcept = default;
1402template <typename Derived>
1414 ) noexcept = default;
1419 ) noexcept = default;
constexpr auto operator=(full_equality_operators_from_basic_equality const &other) &noexcept -> full_equality_operators_from_basic_equality &=default
Default copy assignment is protected.
ARENE_NODISCARD friend constexpr auto operator==(Other const &lhs, Derived const &rhs) noexcept -> bool
Equality comparison operator for instances of Derived and Other.
Definition operators.hpp:105
constexpr full_equality_operators_from_basic_equality() noexcept=default
Default constructor is protected.
constexpr full_ordering_operators_from_less_than_and_equals() noexcept=default
Default constructor is protected.
constexpr auto operator=(full_ordering_operators_from_less_than_and_equals const &other) &noexcept -> full_ordering_operators_from_less_than_and_equals &=default
Helper class that can be inherited from by a class to define the >, <=, >=, == and !...
Definition operators.hpp:677
ARENE_NODISCARD friend constexpr auto operator==(Derived const &lhs, Other const &rhs) noexcept -> bool
Greater-than-or-equal comparison operator for instances of LhsType and RhsType.
Definition operators.hpp:685
ARENE_NODISCARD friend constexpr auto operator<=(Other const &lhs, Derived const &rhs) noexcept -> bool
Less-than-or-equal comparison operator for instances of Derived and Other.
Definition operators.hpp:334
ARENE_NODISCARD friend constexpr auto operator>(Other const &lhs, Derived const &rhs) noexcept -> bool
Greater-than comparison operator for instances of Derived and Other.
Definition operators.hpp:323
ARENE_NODISCARD friend constexpr auto operator>=(Other const &lhs, Derived const &rhs) noexcept -> bool
Greater-than-or-equal comparison operator for instances of Derived and Other.
Definition operators.hpp:345
constexpr auto operator=(full_ordering_operators_from_three_way_compare_and_equals const &other) &noexcept -> full_ordering_operators_from_three_way_compare_and_equals &=default
Default copy assignment is protected.
ARENE_NODISCARD friend constexpr auto operator<(Other const &lhs, Derived const &rhs) noexcept -> bool
Less-than comparison operator for instances of Derived and Other.
Definition operators.hpp:313
constexpr full_ordering_operators_from_three_way_compare_and_equals() noexcept=default
Default constructor is protected.
constexpr full_ordering_operators_from_three_way_compare() noexcept=default
Default constructor is protected.
ARENE_NODISCARD friend constexpr auto operator==(Derived const &lhs, Other const &rhs) noexcept -> bool
Equality comparison operator for instances of Derived and Other.
Definition operators.hpp:448
constexpr auto operator=(full_ordering_operators_from_three_way_compare const &other) &noexcept -> full_ordering_operators_from_three_way_compare &=default
Default copy assignment is protected.
constexpr generic_ordering_from_three_way_compare_and_equals() noexcept=default
Default constructor is protected.
constexpr generic_ordering_from_three_way_compare() noexcept=default
Default constructor is protected.
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if Base is a base class of Derived.
Definition is_base_of.hpp:30
Trait to detect if the two template parameters are the same or not. The value member is true if the t...
Definition is_same.hpp:35
#define ARENE_DEPRECATED_WITH(...)
An alias for the [[deprecated(...)]] attribute, or a no-op if the attribute is not supported.
Definition deprecated.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
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
ARENE_IGNORE_ALL("-Wdeprecated-declarations", "We still want to use the deprecated class in this other deprecated class")
constexpr bool is_nothrow_equality_comparable_v
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
inequality_heuristic
An enumeration used for the return value of fast_inequality_check functions to indicate if two values...
Definition operators.hpp:696
@ may_be_equal_or_not_equal
The values checked may or may not be equal to each other; a more detailed check is required.
Definition operators.hpp:700
@ definitely_not_equal
The two values checked are definitely not equal to each other.
Definition operators.hpp:698
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,...
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26