xref: /llvm-project/libcxx/include/compare (revision b9a2658a3e8bd13b0f9e7a8a440832a95b377216)
10913ca19SEric Fiselier// -*- C++ -*-
2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===//
30913ca19SEric Fiselier//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70913ca19SEric Fiselier//
80913ca19SEric Fiselier//===----------------------------------------------------------------------===//
90913ca19SEric Fiselier
100913ca19SEric Fiselier#ifndef _LIBCPP_COMPARE
110913ca19SEric Fiselier#define _LIBCPP_COMPARE
120913ca19SEric Fiselier
130913ca19SEric Fiselier/*
140913ca19SEric Fiselier    compare synopsis
150913ca19SEric Fiselier
160913ca19SEric Fiseliernamespace std {
170913ca19SEric Fiselier  // [cmp.categories], comparison category types
180913ca19SEric Fiselier  class partial_ordering;
190913ca19SEric Fiselier  class weak_ordering;
200913ca19SEric Fiselier  class strong_ordering;
210913ca19SEric Fiselier
220913ca19SEric Fiselier  // named comparison functions
234ff2fe1dSChristopher Di Bella  constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
244ff2fe1dSChristopher Di Bella  constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
250913ca19SEric Fiselier  constexpr bool is_lt  (partial_ordering cmp) noexcept { return cmp < 0; }
260913ca19SEric Fiselier  constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
270913ca19SEric Fiselier  constexpr bool is_gt  (partial_ordering cmp) noexcept { return cmp > 0; }
280913ca19SEric Fiselier  constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
290913ca19SEric Fiselier
300913ca19SEric Fiselier  // [cmp.common], common comparison category type
310913ca19SEric Fiselier  template<class... Ts>
320913ca19SEric Fiselier  struct common_comparison_category {
330913ca19SEric Fiselier    using type = see below;
340913ca19SEric Fiselier  };
350913ca19SEric Fiselier  template<class... Ts>
360913ca19SEric Fiselier    using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
370913ca19SEric Fiselier
388ce2675bSRuslan Arutyunyan  // [cmp.concept], concept three_way_comparable
398ce2675bSRuslan Arutyunyan  template<class T, class Cat = partial_ordering>
408ce2675bSRuslan Arutyunyan    concept three_way_comparable = see below;
418ce2675bSRuslan Arutyunyan  template<class T, class U, class Cat = partial_ordering>
428ce2675bSRuslan Arutyunyan    concept three_way_comparable_with = see below;
438ce2675bSRuslan Arutyunyan
4438812f4aSArthur O'Dwyer  // [cmp.result], result of three-way comparison
4538812f4aSArthur O'Dwyer  template<class T, class U = T> struct compare_three_way_result;
4638812f4aSArthur O'Dwyer
4738812f4aSArthur O'Dwyer  template<class T, class U = T>
4838812f4aSArthur O'Dwyer    using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
4938812f4aSArthur O'Dwyer
503df094d3SArthur O'Dwyer  // [comparisons.three.way], class compare_three_way
513df094d3SArthur O'Dwyer  struct compare_three_way; // C++20
523df094d3SArthur O'Dwyer
530913ca19SEric Fiselier  // [cmp.alg], comparison algorithms
54bf20a097SArthur O'Dwyer  inline namespace unspecified {
55bf20a097SArthur O'Dwyer    inline constexpr unspecified strong_order = unspecified;
56bf20a097SArthur O'Dwyer    inline constexpr unspecified weak_order = unspecified;
57bf20a097SArthur O'Dwyer    inline constexpr unspecified partial_order = unspecified;
58bf20a097SArthur O'Dwyer    inline constexpr unspecified compare_strong_order_fallback = unspecified;
59bf20a097SArthur O'Dwyer    inline constexpr unspecified compare_weak_order_fallback = unspecified;
60bf20a097SArthur O'Dwyer    inline constexpr unspecified compare_partial_order_fallback = unspecified;
61bf20a097SArthur O'Dwyer  }
62ec789a41SChristopher Di Bella
63ec789a41SChristopher Di Bella  // [cmp.partialord], Class partial_ordering
64ec789a41SChristopher Di Bella  class partial_ordering {
65ec789a41SChristopher Di Bella  public:
66ec789a41SChristopher Di Bella    // valid values
67ec789a41SChristopher Di Bella    static const partial_ordering less;
68ec789a41SChristopher Di Bella    static const partial_ordering equivalent;
69ec789a41SChristopher Di Bella    static const partial_ordering greater;
70ec789a41SChristopher Di Bella    static const partial_ordering unordered;
71ec789a41SChristopher Di Bella
72ec789a41SChristopher Di Bella    // comparisons
73ec789a41SChristopher Di Bella    friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
74ec789a41SChristopher Di Bella    friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
75ec789a41SChristopher Di Bella    friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
76ec789a41SChristopher Di Bella    friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
77ec789a41SChristopher Di Bella    friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
78ec789a41SChristopher Di Bella    friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
79ec789a41SChristopher Di Bella    friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
80ec789a41SChristopher Di Bella    friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
81ec789a41SChristopher Di Bella    friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
82ec789a41SChristopher Di Bella    friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
83ec789a41SChristopher Di Bella    friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
84ec789a41SChristopher Di Bella    friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
85ec789a41SChristopher Di Bella  };
86ec789a41SChristopher Di Bella
87ec789a41SChristopher Di Bella  // [cmp.weakord], Class weak_ordering
88ec789a41SChristopher Di Bella  class weak_ordering {
89ec789a41SChristopher Di Bella  public:
90ec789a41SChristopher Di Bella    // valid values
91ec789a41SChristopher Di Bella    static const weak_ordering less;
92ec789a41SChristopher Di Bella    static const weak_ordering equivalent;
93ec789a41SChristopher Di Bella    static const weak_ordering greater;
94ec789a41SChristopher Di Bella
95ec789a41SChristopher Di Bella    // conversions
96ec789a41SChristopher Di Bella    constexpr operator partial_ordering() const noexcept;
97ec789a41SChristopher Di Bella
98ec789a41SChristopher Di Bella    // comparisons
99ec789a41SChristopher Di Bella    friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
100ec789a41SChristopher Di Bella    friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
101ec789a41SChristopher Di Bella    friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
102ec789a41SChristopher Di Bella    friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
103ec789a41SChristopher Di Bella    friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
104ec789a41SChristopher Di Bella    friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
105ec789a41SChristopher Di Bella    friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
106ec789a41SChristopher Di Bella    friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
107ec789a41SChristopher Di Bella    friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
108ec789a41SChristopher Di Bella    friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
109ec789a41SChristopher Di Bella    friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
110ec789a41SChristopher Di Bella    friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
111ec789a41SChristopher Di Bella  };
112ec789a41SChristopher Di Bella
113ec789a41SChristopher Di Bella  // [cmp.strongord], Class strong_ordering
114ec789a41SChristopher Di Bella  class strong_ordering {
115ec789a41SChristopher Di Bella  public:
116ec789a41SChristopher Di Bella    // valid values
117ec789a41SChristopher Di Bella    static const strong_ordering less;
118ec789a41SChristopher Di Bella    static const strong_ordering equal;
119ec789a41SChristopher Di Bella    static const strong_ordering equivalent;
120ec789a41SChristopher Di Bella    static const strong_ordering greater;
121ec789a41SChristopher Di Bella
122ec789a41SChristopher Di Bella    // conversions
123ec789a41SChristopher Di Bella    constexpr operator partial_ordering() const noexcept;
124ec789a41SChristopher Di Bella    constexpr operator weak_ordering() const noexcept;
125ec789a41SChristopher Di Bella
126ec789a41SChristopher Di Bella    // comparisons
127ec789a41SChristopher Di Bella    friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
128ec789a41SChristopher Di Bella    friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
129ec789a41SChristopher Di Bella    friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
130ec789a41SChristopher Di Bella    friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
131ec789a41SChristopher Di Bella    friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
132ec789a41SChristopher Di Bella    friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
133ec789a41SChristopher Di Bella    friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
134ec789a41SChristopher Di Bella    friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
135ec789a41SChristopher Di Bella    friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
136ec789a41SChristopher Di Bella    friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
137ec789a41SChristopher Di Bella    friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
138ec789a41SChristopher Di Bella    friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
139ec789a41SChristopher Di Bella  };
1400913ca19SEric Fiselier}
1410913ca19SEric Fiselier*/
1420913ca19SEric Fiselier
143*b9a2658aSNikolas Klauser#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
144*b9a2658aSNikolas Klauser#  include <__cxx03/compare>
145*b9a2658aSNikolas Klauser#else
146d5c654b5SNikolas Klauser#  include <__config>
147d5c654b5SNikolas Klauser
148d5c654b5SNikolas Klauser#  if _LIBCPP_STD_VER >= 20
14961c35fb0SRuslan Arutyunyan#    include <__compare/common_comparison_category.h>
150bf20a097SArthur O'Dwyer#    include <__compare/compare_partial_order_fallback.h>
151bf20a097SArthur O'Dwyer#    include <__compare/compare_strong_order_fallback.h>
1523df094d3SArthur O'Dwyer#    include <__compare/compare_three_way.h>
15338812f4aSArthur O'Dwyer#    include <__compare/compare_three_way_result.h>
154bf20a097SArthur O'Dwyer#    include <__compare/compare_weak_order_fallback.h>
155969359e3SArthur O'Dwyer#    include <__compare/is_eq.h>
15661c35fb0SRuslan Arutyunyan#    include <__compare/ordering.h>
157d8380ad9SArthur O'Dwyer#    include <__compare/partial_order.h>
158d8380ad9SArthur O'Dwyer#    include <__compare/strong_order.h>
1599c0efc8aSMark de Wever#    include <__compare/synth_three_way.h>
1608ce2675bSRuslan Arutyunyan#    include <__compare/three_way_comparable.h>
161d8380ad9SArthur O'Dwyer#    include <__compare/weak_order.h>
162d5c654b5SNikolas Klauser#  endif // _LIBCPP_STD_VER >= 20
163d5c654b5SNikolas Klauser
164bd6e6846SMark de Wever#  include <version>
1650913ca19SEric Fiselier
166413c3c4fSArthur O'Dwyer#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
167413c3c4fSArthur O'Dwyer#    pragma GCC system_header
168413c3c4fSArthur O'Dwyer#  endif
169413c3c4fSArthur O'Dwyer
170e0a66116SNikolas Klauser#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1711b5f6916SNikolas Klauser#    include <cmath>
172e99c4906SNikolas Klauser#    include <cstddef>
173e0a66116SNikolas Klauser#    include <type_traits>
174e0a66116SNikolas Klauser#  endif
175*b9a2658aSNikolas Klauser#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
176e0a66116SNikolas Klauser
1770913ca19SEric Fiselier#endif // _LIBCPP_COMPARE
178