1// -*- C++ -*-
2//===-------------------------- compare -----------------------------------===//
3//
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
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_COMPARE
11#define _LIBCPP_COMPARE
12
13/*
14    compare synopsis
15
16namespace std {
17  // [cmp.categories], comparison category types
18  class partial_ordering;
19  class weak_ordering;
20  class strong_ordering;
21
22  // named comparison functions
23  constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
24  constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
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
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
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
50  // [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);
54
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  };
132}
133*/
134
135#include <__compare/common_comparison_category.h>
136#include <__compare/compare_three_way_result.h>
137#include <__compare/ordering.h>
138#include <__compare/three_way_comparable.h>
139#include <__config>
140
141#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
142#pragma GCC system_header
143#endif
144
145_LIBCPP_BEGIN_NAMESPACE_STD
146
147#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
148
149// [cmp.alg], comparison algorithms
150// TODO: unimplemented
151template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
152template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
153template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
154
155#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
156
157_LIBCPP_END_NAMESPACE_STD
158
159#endif // _LIBCPP_COMPARE
160