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