Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_COMPARE |
| 11 | #define _LIBCPP_COMPARE |
| 12 | |
| 13 | /* |
| 14 | compare synopsis |
| 15 | |
| 16 | namespace std { |
| 17 | // [cmp.categories], comparison category types |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 18 | class partial_ordering; |
| 19 | class weak_ordering; |
| 20 | class strong_ordering; |
| 21 | |
| 22 | // named comparison functions |
Arthur O'Dwyer | 0241467 | 2021-07-29 01:34:31 -0400 | [diff] [blame] | 23 | constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; } |
| 24 | constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; } |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 25 | constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; } |
| 26 | constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; } |
| 27 | constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; } |
| 28 | constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; } |
| 29 | |
| 30 | // [cmp.common], common comparison category type |
| 31 | template<class... Ts> |
| 32 | struct common_comparison_category { |
| 33 | using type = see below; |
| 34 | }; |
| 35 | template<class... Ts> |
| 36 | using common_comparison_category_t = typename common_comparison_category<Ts...>::type; |
| 37 | |
Ruslan Arutyunyan | ebd52ba | 2021-09-04 20:16:18 -0700 | [diff] [blame] | 38 | // [cmp.concept], concept three_way_comparable |
| 39 | template<class T, class Cat = partial_ordering> |
| 40 | concept three_way_comparable = see below; |
| 41 | template<class T, class U, class Cat = partial_ordering> |
| 42 | concept three_way_comparable_with = see below; |
| 43 | |
Arthur O'Dwyer | 77eb34e | 2021-07-29 00:03:01 -0400 | [diff] [blame] | 44 | // [cmp.result], result of three-way comparison |
| 45 | template<class T, class U = T> struct compare_three_way_result; |
| 46 | |
| 47 | template<class T, class U = T> |
| 48 | using compare_three_way_result_t = typename compare_three_way_result<T, U>::type; |
| 49 | |
Arthur O'Dwyer | fbf9aab | 2021-07-28 23:40:29 -0400 | [diff] [blame] | 50 | // [comparisons.three.way], class compare_three_way |
| 51 | struct compare_three_way; // C++20 |
| 52 | |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 53 | // [cmp.alg], comparison algorithms |
| 54 | template<class T> constexpr strong_ordering strong_order(const T& a, const T& b); |
| 55 | template<class T> constexpr weak_ordering weak_order(const T& a, const T& b); |
| 56 | template<class T> constexpr partial_ordering partial_order(const T& a, const T& b); |
Christopher Di Bella | 3f33a1e | 2020-06-18 10:17:57 -0400 | [diff] [blame] | 57 | |
| 58 | // [cmp.partialord], Class partial_ordering |
| 59 | class partial_ordering { |
| 60 | public: |
| 61 | // valid values |
| 62 | static const partial_ordering less; |
| 63 | static const partial_ordering equivalent; |
| 64 | static const partial_ordering greater; |
| 65 | static const partial_ordering unordered; |
| 66 | |
| 67 | // comparisons |
| 68 | friend constexpr bool operator==(partial_ordering v, unspecified) noexcept; |
| 69 | friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default; |
| 70 | friend constexpr bool operator< (partial_ordering v, unspecified) noexcept; |
| 71 | friend constexpr bool operator> (partial_ordering v, unspecified) noexcept; |
| 72 | friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept; |
| 73 | friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept; |
| 74 | friend constexpr bool operator< (unspecified, partial_ordering v) noexcept; |
| 75 | friend constexpr bool operator> (unspecified, partial_ordering v) noexcept; |
| 76 | friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept; |
| 77 | friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept; |
| 78 | friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept; |
| 79 | friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept; |
| 80 | }; |
| 81 | |
| 82 | // [cmp.weakord], Class weak_ordering |
| 83 | class weak_ordering { |
| 84 | public: |
| 85 | // valid values |
| 86 | static const weak_ordering less; |
| 87 | static const weak_ordering equivalent; |
| 88 | static const weak_ordering greater; |
| 89 | |
| 90 | // conversions |
| 91 | constexpr operator partial_ordering() const noexcept; |
| 92 | |
| 93 | // comparisons |
| 94 | friend constexpr bool operator==(weak_ordering v, unspecified) noexcept; |
| 95 | friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default; |
| 96 | friend constexpr bool operator< (weak_ordering v, unspecified) noexcept; |
| 97 | friend constexpr bool operator> (weak_ordering v, unspecified) noexcept; |
| 98 | friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept; |
| 99 | friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept; |
| 100 | friend constexpr bool operator< (unspecified, weak_ordering v) noexcept; |
| 101 | friend constexpr bool operator> (unspecified, weak_ordering v) noexcept; |
| 102 | friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept; |
| 103 | friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept; |
| 104 | friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept; |
| 105 | friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept; |
| 106 | }; |
| 107 | |
| 108 | // [cmp.strongord], Class strong_ordering |
| 109 | class strong_ordering { |
| 110 | public: |
| 111 | // valid values |
| 112 | static const strong_ordering less; |
| 113 | static const strong_ordering equal; |
| 114 | static const strong_ordering equivalent; |
| 115 | static const strong_ordering greater; |
| 116 | |
| 117 | // conversions |
| 118 | constexpr operator partial_ordering() const noexcept; |
| 119 | constexpr operator weak_ordering() const noexcept; |
| 120 | |
| 121 | // comparisons |
| 122 | friend constexpr bool operator==(strong_ordering v, unspecified) noexcept; |
| 123 | friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default; |
| 124 | friend constexpr bool operator< (strong_ordering v, unspecified) noexcept; |
| 125 | friend constexpr bool operator> (strong_ordering v, unspecified) noexcept; |
| 126 | friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept; |
| 127 | friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept; |
| 128 | friend constexpr bool operator< (unspecified, strong_ordering v) noexcept; |
| 129 | friend constexpr bool operator> (unspecified, strong_ordering v) noexcept; |
| 130 | friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept; |
| 131 | friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept; |
| 132 | friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept; |
| 133 | friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept; |
| 134 | }; |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 135 | } |
| 136 | */ |
| 137 | |
Ruslan Arutyunyan | 1babff3 | 2021-07-28 22:05:46 -0400 | [diff] [blame] | 138 | #include <__compare/common_comparison_category.h> |
Arthur O'Dwyer | fbf9aab | 2021-07-28 23:40:29 -0400 | [diff] [blame] | 139 | #include <__compare/compare_three_way.h> |
Arthur O'Dwyer | 77eb34e | 2021-07-29 00:03:01 -0400 | [diff] [blame] | 140 | #include <__compare/compare_three_way_result.h> |
Arthur O'Dwyer | 5eeeb7b | 2021-09-27 00:48:39 -0400 | [diff] [blame] | 141 | #include <__compare/is_eq.h> |
Ruslan Arutyunyan | 1babff3 | 2021-07-28 22:05:46 -0400 | [diff] [blame] | 142 | #include <__compare/ordering.h> |
Arthur O'Dwyer | b85724e | 2021-07-28 22:04:18 -0400 | [diff] [blame] | 143 | #include <__compare/partial_order.h> |
| 144 | #include <__compare/strong_order.h> |
Ruslan Arutyunyan | ebd52ba | 2021-09-04 20:16:18 -0700 | [diff] [blame] | 145 | #include <__compare/three_way_comparable.h> |
Arthur O'Dwyer | b85724e | 2021-07-28 22:04:18 -0400 | [diff] [blame] | 146 | #include <__compare/weak_order.h> |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 147 | #include <__config> |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 148 | |
Arthur O'Dwyer | e387462 | 2021-12-05 13:08:36 -0500 | [diff] [blame] | 149 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 150 | #pragma GCC system_header |
| 151 | #endif |
| 152 | |
Eric Fiselier | e0074fc | 2018-04-06 21:37:23 +0000 | [diff] [blame] | 153 | #endif // _LIBCPP_COMPARE |