blob: ca1f57439b6b2a7a6682ef4b26f4732663777fcf [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
Eric Fiseliere0074fc2018-04-06 21:37:23 +000050 // [cmp.alg], comparison algorithms
51 template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
52 template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
53 template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
Christopher Di Bella3f33a1e2020-06-18 10:17:57 -040054
55 // [cmp.partialord], Class partial_ordering
56 class partial_ordering {
57 public:
58 // valid values
59 static const partial_ordering less;
60 static const partial_ordering equivalent;
61 static const partial_ordering greater;
62 static const partial_ordering unordered;
63
64 // comparisons
65 friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
66 friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
67 friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
68 friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
69 friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
70 friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
71 friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
72 friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
73 friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
74 friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
75 friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
76 friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
77 };
78
79 // [cmp.weakord], Class weak_ordering
80 class weak_ordering {
81 public:
82 // valid values
83 static const weak_ordering less;
84 static const weak_ordering equivalent;
85 static const weak_ordering greater;
86
87 // conversions
88 constexpr operator partial_ordering() const noexcept;
89
90 // comparisons
91 friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
92 friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
93 friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
94 friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
95 friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
96 friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
97 friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
98 friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
99 friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
100 friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
101 friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
102 friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
103 };
104
105 // [cmp.strongord], Class strong_ordering
106 class strong_ordering {
107 public:
108 // valid values
109 static const strong_ordering less;
110 static const strong_ordering equal;
111 static const strong_ordering equivalent;
112 static const strong_ordering greater;
113
114 // conversions
115 constexpr operator partial_ordering() const noexcept;
116 constexpr operator weak_ordering() const noexcept;
117
118 // comparisons
119 friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
120 friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
121 friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
122 friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
123 friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
124 friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
125 friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
126 friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
127 friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
128 friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
129 friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
130 friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
131 };
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000132}
133*/
134
Ruslan Arutyunyan1babff32021-07-28 22:05:46 -0400135#include <__compare/common_comparison_category.h>
Arthur O'Dwyer77eb34e2021-07-29 00:03:01 -0400136#include <__compare/compare_three_way_result.h>
Arthur O'Dwyer5eeeb7b2021-09-27 00:48:39 -0400137#include <__compare/is_eq.h>
Ruslan Arutyunyan1babff32021-07-28 22:05:46 -0400138#include <__compare/ordering.h>
Ruslan Arutyunyanebd52ba2021-09-04 20:16:18 -0700139#include <__compare/three_way_comparable.h>
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000140#include <__config>
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000141
142#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
143#pragma GCC system_header
144#endif
145
146_LIBCPP_BEGIN_NAMESPACE_STD
147
Christopher Di Bellaea4a60c2021-04-12 20:55:05 +0000148#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000149
150// [cmp.alg], comparison algorithms
151// TODO: unimplemented
152template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
153template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
154template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000155
Christopher Di Bellaea4a60c2021-04-12 20:55:05 +0000156#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000157
158_LIBCPP_END_NAMESPACE_STD
159
160#endif // _LIBCPP_COMPARE