blob: ddb8313547512f380384630b849d7fcfe43fcf58 [file] [log] [blame]
Eric Fiseliere0074fc2018-04-06 21:37:23 +00001// -*- C++ -*-
2//===-------------------------- compare -----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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 Fiseliere0074fc2018-04-06 21:37:23 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_COMPARE
11#define _LIBCPP_COMPARE
12
13/*
14 compare synopsis
15
16namespace std {
17 // [cmp.categories], comparison category types
Eric Fiseliere0074fc2018-04-06 21:37:23 +000018 class partial_ordering;
19 class weak_ordering;
20 class strong_ordering;
21
22 // named comparison functions
Arthur O'Dwyer02414672021-07-29 01:34:31 -040023 constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
24 constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
Eric Fiseliere0074fc2018-04-06 21:37:23 +000025 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 Arutyunyanebd52ba2021-09-04 20:16:18 -070038 // [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'Dwyer77eb34e2021-07-29 00:03:01 -040044 // [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'Dwyerfbf9aab2021-07-28 23:40:29 -040050 // [comparisons.three.way], class compare_three_way
51 struct compare_three_way; // C++20
52
Eric Fiseliere0074fc2018-04-06 21:37:23 +000053 // [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 Bella3f33a1e2020-06-18 10:17:57 -040057
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 Fiseliere0074fc2018-04-06 21:37:23 +0000135}
136*/
137
Ruslan Arutyunyan1babff32021-07-28 22:05:46 -0400138#include <__compare/common_comparison_category.h>
Arthur O'Dwyerfbf9aab2021-07-28 23:40:29 -0400139#include <__compare/compare_three_way.h>
Arthur O'Dwyer77eb34e2021-07-29 00:03:01 -0400140#include <__compare/compare_three_way_result.h>
Arthur O'Dwyer5eeeb7b2021-09-27 00:48:39 -0400141#include <__compare/is_eq.h>
Ruslan Arutyunyan1babff32021-07-28 22:05:46 -0400142#include <__compare/ordering.h>
Ruslan Arutyunyanebd52ba2021-09-04 20:16:18 -0700143#include <__compare/three_way_comparable.h>
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000144#include <__config>
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000145
146#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
147#pragma GCC system_header
148#endif
149
150_LIBCPP_BEGIN_NAMESPACE_STD
151
Christopher Di Bellaea4a60c2021-04-12 20:55:05 +0000152#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000153
154// [cmp.alg], comparison algorithms
155// TODO: unimplemented
156template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
157template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
158template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000159
Christopher Di Bellaea4a60c2021-04-12 20:55:05 +0000160#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000161
162_LIBCPP_END_NAMESPACE_STD
163
164#endif // _LIBCPP_COMPARE