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.alg], comparison algorithms
39  template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
40  template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
41  template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
42
43  // [cmp.partialord], Class partial_ordering
44  class partial_ordering {
45  public:
46    // valid values
47    static const partial_ordering less;
48    static const partial_ordering equivalent;
49    static const partial_ordering greater;
50    static const partial_ordering unordered;
51
52    // comparisons
53    friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
54    friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
55    friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
56    friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
57    friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
58    friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
59    friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
60    friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
61    friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
62    friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
63    friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
64    friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
65  };
66
67  // [cmp.weakord], Class weak_ordering
68  class weak_ordering {
69  public:
70    // valid values
71    static const weak_ordering less;
72    static const weak_ordering equivalent;
73    static const weak_ordering greater;
74
75    // conversions
76    constexpr operator partial_ordering() const noexcept;
77
78    // comparisons
79    friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
80    friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
81    friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
82    friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
83    friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
84    friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
85    friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
86    friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
87    friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
88    friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
89    friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
90    friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
91  };
92
93  // [cmp.strongord], Class strong_ordering
94  class strong_ordering {
95  public:
96    // valid values
97    static const strong_ordering less;
98    static const strong_ordering equal;
99    static const strong_ordering equivalent;
100    static const strong_ordering greater;
101
102    // conversions
103    constexpr operator partial_ordering() const noexcept;
104    constexpr operator weak_ordering() const noexcept;
105
106    // comparisons
107    friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
108    friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
109    friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
110    friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
111    friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
112    friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
113    friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
114    friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
115    friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
116    friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
117    friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
118    friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
119  };
120}
121*/
122
123#include <__compare/common_comparison_category.h>
124#include <__compare/ordering.h>
125#include <__config>
126#include <type_traits>
127
128#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
129#pragma GCC system_header
130#endif
131
132_LIBCPP_BEGIN_NAMESPACE_STD
133
134#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
135
136// [cmp.alg], comparison algorithms
137// TODO: unimplemented
138template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
139template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
140template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
141
142#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
143
144_LIBCPP_END_NAMESPACE_STD
145
146#endif // _LIBCPP_COMPARE
147