xref: /openbsd-src/gnu/llvm/libcxx/include/compare (revision 4bdff4bed0e3d54e55670334c7d0077db4170f86)
146035553Spatrick// -*- C++ -*-
2*4bdff4beSrobert//===----------------------------------------------------------------------===//
346035553Spatrick//
446035553Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
546035553Spatrick// See https://llvm.org/LICENSE.txt for license information.
646035553Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
746035553Spatrick//
846035553Spatrick//===----------------------------------------------------------------------===//
946035553Spatrick
1046035553Spatrick#ifndef _LIBCPP_COMPARE
1146035553Spatrick#define _LIBCPP_COMPARE
1246035553Spatrick
1346035553Spatrick/*
1446035553Spatrick    compare synopsis
1546035553Spatrick
1646035553Spatricknamespace std {
1746035553Spatrick  // [cmp.categories], comparison category types
1846035553Spatrick  class partial_ordering;
1946035553Spatrick  class weak_ordering;
2046035553Spatrick  class strong_ordering;
2146035553Spatrick
2246035553Spatrick  // named comparison functions
2376d0caaeSpatrick  constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
2476d0caaeSpatrick  constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
2546035553Spatrick  constexpr bool is_lt  (partial_ordering cmp) noexcept { return cmp < 0; }
2646035553Spatrick  constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
2746035553Spatrick  constexpr bool is_gt  (partial_ordering cmp) noexcept { return cmp > 0; }
2846035553Spatrick  constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
2946035553Spatrick
3046035553Spatrick  // [cmp.common], common comparison category type
3146035553Spatrick  template<class... Ts>
3246035553Spatrick  struct common_comparison_category {
3346035553Spatrick    using type = see below;
3446035553Spatrick  };
3546035553Spatrick  template<class... Ts>
3646035553Spatrick    using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
3746035553Spatrick
38*4bdff4beSrobert  // [cmp.concept], concept three_way_comparable
39*4bdff4beSrobert  template<class T, class Cat = partial_ordering>
40*4bdff4beSrobert    concept three_way_comparable = see below;
41*4bdff4beSrobert  template<class T, class U, class Cat = partial_ordering>
42*4bdff4beSrobert    concept three_way_comparable_with = see below;
43*4bdff4beSrobert
44*4bdff4beSrobert  // [cmp.result], result of three-way comparison
45*4bdff4beSrobert  template<class T, class U = T> struct compare_three_way_result;
46*4bdff4beSrobert
47*4bdff4beSrobert  template<class T, class U = T>
48*4bdff4beSrobert    using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
49*4bdff4beSrobert
50*4bdff4beSrobert  // [comparisons.three.way], class compare_three_way
51*4bdff4beSrobert  struct compare_three_way; // C++20
52*4bdff4beSrobert
5346035553Spatrick  // [cmp.alg], comparison algorithms
54*4bdff4beSrobert  inline namespace unspecified {
55*4bdff4beSrobert    inline constexpr unspecified strong_order = unspecified;
56*4bdff4beSrobert    inline constexpr unspecified weak_order = unspecified;
57*4bdff4beSrobert    inline constexpr unspecified partial_order = unspecified;
58*4bdff4beSrobert    inline constexpr unspecified compare_strong_order_fallback = unspecified;
59*4bdff4beSrobert    inline constexpr unspecified compare_weak_order_fallback = unspecified;
60*4bdff4beSrobert    inline constexpr unspecified compare_partial_order_fallback = unspecified;
61*4bdff4beSrobert  }
62037e7968Spatrick
63037e7968Spatrick  // [cmp.partialord], Class partial_ordering
64037e7968Spatrick  class partial_ordering {
65037e7968Spatrick  public:
66037e7968Spatrick    // valid values
67037e7968Spatrick    static const partial_ordering less;
68037e7968Spatrick    static const partial_ordering equivalent;
69037e7968Spatrick    static const partial_ordering greater;
70037e7968Spatrick    static const partial_ordering unordered;
71037e7968Spatrick
72037e7968Spatrick    // comparisons
73037e7968Spatrick    friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
74037e7968Spatrick    friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
75037e7968Spatrick    friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
76037e7968Spatrick    friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
77037e7968Spatrick    friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
78037e7968Spatrick    friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
79037e7968Spatrick    friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
80037e7968Spatrick    friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
81037e7968Spatrick    friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
82037e7968Spatrick    friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
83037e7968Spatrick    friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
84037e7968Spatrick    friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
85037e7968Spatrick  };
86037e7968Spatrick
87037e7968Spatrick  // [cmp.weakord], Class weak_ordering
88037e7968Spatrick  class weak_ordering {
89037e7968Spatrick  public:
90037e7968Spatrick    // valid values
91037e7968Spatrick    static const weak_ordering less;
92037e7968Spatrick    static const weak_ordering equivalent;
93037e7968Spatrick    static const weak_ordering greater;
94037e7968Spatrick
95037e7968Spatrick    // conversions
96037e7968Spatrick    constexpr operator partial_ordering() const noexcept;
97037e7968Spatrick
98037e7968Spatrick    // comparisons
99037e7968Spatrick    friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
100037e7968Spatrick    friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
101037e7968Spatrick    friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
102037e7968Spatrick    friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
103037e7968Spatrick    friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
104037e7968Spatrick    friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
105037e7968Spatrick    friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
106037e7968Spatrick    friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
107037e7968Spatrick    friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
108037e7968Spatrick    friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
109037e7968Spatrick    friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
110037e7968Spatrick    friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
111037e7968Spatrick  };
112037e7968Spatrick
113037e7968Spatrick  // [cmp.strongord], Class strong_ordering
114037e7968Spatrick  class strong_ordering {
115037e7968Spatrick  public:
116037e7968Spatrick    // valid values
117037e7968Spatrick    static const strong_ordering less;
118037e7968Spatrick    static const strong_ordering equal;
119037e7968Spatrick    static const strong_ordering equivalent;
120037e7968Spatrick    static const strong_ordering greater;
121037e7968Spatrick
122037e7968Spatrick    // conversions
123037e7968Spatrick    constexpr operator partial_ordering() const noexcept;
124037e7968Spatrick    constexpr operator weak_ordering() const noexcept;
125037e7968Spatrick
126037e7968Spatrick    // comparisons
127037e7968Spatrick    friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
128037e7968Spatrick    friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
129037e7968Spatrick    friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
130037e7968Spatrick    friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
131037e7968Spatrick    friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
132037e7968Spatrick    friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
133037e7968Spatrick    friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
134037e7968Spatrick    friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
135037e7968Spatrick    friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
136037e7968Spatrick    friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
137037e7968Spatrick    friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
138037e7968Spatrick    friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
139037e7968Spatrick  };
14046035553Spatrick}
14146035553Spatrick*/
14246035553Spatrick
143*4bdff4beSrobert#include <__assert> // all public C++ headers provide the assertion handler
144*4bdff4beSrobert#include <__compare/common_comparison_category.h>
145*4bdff4beSrobert#include <__compare/compare_partial_order_fallback.h>
146*4bdff4beSrobert#include <__compare/compare_strong_order_fallback.h>
147*4bdff4beSrobert#include <__compare/compare_three_way.h>
148*4bdff4beSrobert#include <__compare/compare_three_way_result.h>
149*4bdff4beSrobert#include <__compare/compare_weak_order_fallback.h>
150*4bdff4beSrobert#include <__compare/is_eq.h>
151*4bdff4beSrobert#include <__compare/ordering.h>
152*4bdff4beSrobert#include <__compare/partial_order.h>
153*4bdff4beSrobert#include <__compare/strong_order.h>
154*4bdff4beSrobert#include <__compare/three_way_comparable.h>
155*4bdff4beSrobert#include <__compare/weak_order.h>
15646035553Spatrick#include <__config>
157*4bdff4beSrobert#include <version>
15846035553Spatrick
159*4bdff4beSrobert#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16046035553Spatrick#  pragma GCC system_header
16146035553Spatrick#endif
16246035553Spatrick
163*4bdff4beSrobert#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
164*4bdff4beSrobert#  include <type_traits>
165*4bdff4beSrobert#endif
16646035553Spatrick
16746035553Spatrick#endif // _LIBCPP_COMPARE
168