blob: f6814542a0c3ca91a31ffd346a566dac0da7111f [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
Arthur O'Dwyer77eb34e2021-07-29 00:03:01 -040038 // [cmp.result], result of three-way comparison
39 template<class T, class U = T> struct compare_three_way_result;
40
41 template<class T, class U = T>
42 using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
43
Eric Fiseliere0074fc2018-04-06 21:37:23 +000044 // [cmp.alg], comparison algorithms
45 template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
46 template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
47 template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
Christopher Di Bella3f33a1e2020-06-18 10:17:57 -040048
49 // [cmp.partialord], Class partial_ordering
50 class partial_ordering {
51 public:
52 // valid values
53 static const partial_ordering less;
54 static const partial_ordering equivalent;
55 static const partial_ordering greater;
56 static const partial_ordering unordered;
57
58 // comparisons
59 friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
60 friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
61 friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
62 friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
63 friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
64 friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
65 friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
66 friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
67 friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
68 friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
69 friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
70 friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
71 };
72
73 // [cmp.weakord], Class weak_ordering
74 class weak_ordering {
75 public:
76 // valid values
77 static const weak_ordering less;
78 static const weak_ordering equivalent;
79 static const weak_ordering greater;
80
81 // conversions
82 constexpr operator partial_ordering() const noexcept;
83
84 // comparisons
85 friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
86 friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
87 friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
88 friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
89 friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
90 friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
91 friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
92 friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
93 friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
94 friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
95 friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
96 friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
97 };
98
99 // [cmp.strongord], Class strong_ordering
100 class strong_ordering {
101 public:
102 // valid values
103 static const strong_ordering less;
104 static const strong_ordering equal;
105 static const strong_ordering equivalent;
106 static const strong_ordering greater;
107
108 // conversions
109 constexpr operator partial_ordering() const noexcept;
110 constexpr operator weak_ordering() const noexcept;
111
112 // comparisons
113 friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
114 friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
115 friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
116 friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
117 friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
118 friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
119 friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
120 friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
121 friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
122 friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
123 friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
124 friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
125 };
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000126}
127*/
128
Ruslan Arutyunyan1babff32021-07-28 22:05:46 -0400129#include <__compare/common_comparison_category.h>
Arthur O'Dwyer77eb34e2021-07-29 00:03:01 -0400130#include <__compare/compare_three_way_result.h>
Ruslan Arutyunyan1babff32021-07-28 22:05:46 -0400131#include <__compare/ordering.h>
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000132#include <__config>
133#include <type_traits>
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000134
135#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
136#pragma GCC system_header
137#endif
138
139_LIBCPP_BEGIN_NAMESPACE_STD
140
Christopher Di Bellaea4a60c2021-04-12 20:55:05 +0000141#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000142
143// [cmp.alg], comparison algorithms
144// TODO: unimplemented
145template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
146template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
147template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000148
Christopher Di Bellaea4a60c2021-04-12 20:55:05 +0000149#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
Eric Fiseliere0074fc2018-04-06 21:37:23 +0000150
151_LIBCPP_END_NAMESPACE_STD
152
153#endif // _LIBCPP_COMPARE