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