10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_COMPARE 110b57cec5SDimitry Andric#define _LIBCPP_COMPARE 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric compare synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std { 170b57cec5SDimitry Andric // [cmp.categories], comparison category types 180b57cec5SDimitry Andric class partial_ordering; 190b57cec5SDimitry Andric class weak_ordering; 200b57cec5SDimitry Andric class strong_ordering; 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric // named comparison functions 23fe6060f1SDimitry Andric constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; } 24fe6060f1SDimitry Andric constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; } 250b57cec5SDimitry Andric constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; } 260b57cec5SDimitry Andric constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; } 270b57cec5SDimitry Andric constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; } 280b57cec5SDimitry Andric constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; } 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric // [cmp.common], common comparison category type 310b57cec5SDimitry Andric template<class... Ts> 320b57cec5SDimitry Andric struct common_comparison_category { 330b57cec5SDimitry Andric using type = see below; 340b57cec5SDimitry Andric }; 350b57cec5SDimitry Andric template<class... Ts> 360b57cec5SDimitry Andric using common_comparison_category_t = typename common_comparison_category<Ts...>::type; 370b57cec5SDimitry Andric 38349cc55cSDimitry Andric // [cmp.concept], concept three_way_comparable 39349cc55cSDimitry Andric template<class T, class Cat = partial_ordering> 40349cc55cSDimitry Andric concept three_way_comparable = see below; 41349cc55cSDimitry Andric template<class T, class U, class Cat = partial_ordering> 42349cc55cSDimitry Andric concept three_way_comparable_with = see below; 43349cc55cSDimitry Andric 44349cc55cSDimitry Andric // [cmp.result], result of three-way comparison 45349cc55cSDimitry Andric template<class T, class U = T> struct compare_three_way_result; 46349cc55cSDimitry Andric 47349cc55cSDimitry Andric template<class T, class U = T> 48349cc55cSDimitry Andric using compare_three_way_result_t = typename compare_three_way_result<T, U>::type; 49349cc55cSDimitry Andric 50349cc55cSDimitry Andric // [comparisons.three.way], class compare_three_way 51349cc55cSDimitry Andric struct compare_three_way; // C++20 52349cc55cSDimitry Andric 530b57cec5SDimitry Andric // [cmp.alg], comparison algorithms 541fd87a68SDimitry Andric inline namespace unspecified { 551fd87a68SDimitry Andric inline constexpr unspecified strong_order = unspecified; 561fd87a68SDimitry Andric inline constexpr unspecified weak_order = unspecified; 571fd87a68SDimitry Andric inline constexpr unspecified partial_order = unspecified; 581fd87a68SDimitry Andric inline constexpr unspecified compare_strong_order_fallback = unspecified; 591fd87a68SDimitry Andric inline constexpr unspecified compare_weak_order_fallback = unspecified; 601fd87a68SDimitry Andric inline constexpr unspecified compare_partial_order_fallback = unspecified; 611fd87a68SDimitry Andric } 625ffd83dbSDimitry Andric 635ffd83dbSDimitry Andric // [cmp.partialord], Class partial_ordering 645ffd83dbSDimitry Andric class partial_ordering { 655ffd83dbSDimitry Andric public: 665ffd83dbSDimitry Andric // valid values 675ffd83dbSDimitry Andric static const partial_ordering less; 685ffd83dbSDimitry Andric static const partial_ordering equivalent; 695ffd83dbSDimitry Andric static const partial_ordering greater; 705ffd83dbSDimitry Andric static const partial_ordering unordered; 715ffd83dbSDimitry Andric 725ffd83dbSDimitry Andric // comparisons 735ffd83dbSDimitry Andric friend constexpr bool operator==(partial_ordering v, unspecified) noexcept; 745ffd83dbSDimitry Andric friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default; 755ffd83dbSDimitry Andric friend constexpr bool operator< (partial_ordering v, unspecified) noexcept; 765ffd83dbSDimitry Andric friend constexpr bool operator> (partial_ordering v, unspecified) noexcept; 775ffd83dbSDimitry Andric friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept; 785ffd83dbSDimitry Andric friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept; 795ffd83dbSDimitry Andric friend constexpr bool operator< (unspecified, partial_ordering v) noexcept; 805ffd83dbSDimitry Andric friend constexpr bool operator> (unspecified, partial_ordering v) noexcept; 815ffd83dbSDimitry Andric friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept; 825ffd83dbSDimitry Andric friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept; 835ffd83dbSDimitry Andric friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept; 845ffd83dbSDimitry Andric friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept; 855ffd83dbSDimitry Andric }; 865ffd83dbSDimitry Andric 875ffd83dbSDimitry Andric // [cmp.weakord], Class weak_ordering 885ffd83dbSDimitry Andric class weak_ordering { 895ffd83dbSDimitry Andric public: 905ffd83dbSDimitry Andric // valid values 915ffd83dbSDimitry Andric static const weak_ordering less; 925ffd83dbSDimitry Andric static const weak_ordering equivalent; 935ffd83dbSDimitry Andric static const weak_ordering greater; 945ffd83dbSDimitry Andric 955ffd83dbSDimitry Andric // conversions 965ffd83dbSDimitry Andric constexpr operator partial_ordering() const noexcept; 975ffd83dbSDimitry Andric 985ffd83dbSDimitry Andric // comparisons 995ffd83dbSDimitry Andric friend constexpr bool operator==(weak_ordering v, unspecified) noexcept; 1005ffd83dbSDimitry Andric friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default; 1015ffd83dbSDimitry Andric friend constexpr bool operator< (weak_ordering v, unspecified) noexcept; 1025ffd83dbSDimitry Andric friend constexpr bool operator> (weak_ordering v, unspecified) noexcept; 1035ffd83dbSDimitry Andric friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept; 1045ffd83dbSDimitry Andric friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept; 1055ffd83dbSDimitry Andric friend constexpr bool operator< (unspecified, weak_ordering v) noexcept; 1065ffd83dbSDimitry Andric friend constexpr bool operator> (unspecified, weak_ordering v) noexcept; 1075ffd83dbSDimitry Andric friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept; 1085ffd83dbSDimitry Andric friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept; 1095ffd83dbSDimitry Andric friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept; 1105ffd83dbSDimitry Andric friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept; 1115ffd83dbSDimitry Andric }; 1125ffd83dbSDimitry Andric 1135ffd83dbSDimitry Andric // [cmp.strongord], Class strong_ordering 1145ffd83dbSDimitry Andric class strong_ordering { 1155ffd83dbSDimitry Andric public: 1165ffd83dbSDimitry Andric // valid values 1175ffd83dbSDimitry Andric static const strong_ordering less; 1185ffd83dbSDimitry Andric static const strong_ordering equal; 1195ffd83dbSDimitry Andric static const strong_ordering equivalent; 1205ffd83dbSDimitry Andric static const strong_ordering greater; 1215ffd83dbSDimitry Andric 1225ffd83dbSDimitry Andric // conversions 1235ffd83dbSDimitry Andric constexpr operator partial_ordering() const noexcept; 1245ffd83dbSDimitry Andric constexpr operator weak_ordering() const noexcept; 1255ffd83dbSDimitry Andric 1265ffd83dbSDimitry Andric // comparisons 1275ffd83dbSDimitry Andric friend constexpr bool operator==(strong_ordering v, unspecified) noexcept; 1285ffd83dbSDimitry Andric friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default; 1295ffd83dbSDimitry Andric friend constexpr bool operator< (strong_ordering v, unspecified) noexcept; 1305ffd83dbSDimitry Andric friend constexpr bool operator> (strong_ordering v, unspecified) noexcept; 1315ffd83dbSDimitry Andric friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept; 1325ffd83dbSDimitry Andric friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept; 1335ffd83dbSDimitry Andric friend constexpr bool operator< (unspecified, strong_ordering v) noexcept; 1345ffd83dbSDimitry Andric friend constexpr bool operator> (unspecified, strong_ordering v) noexcept; 1355ffd83dbSDimitry Andric friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept; 1365ffd83dbSDimitry Andric friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept; 1375ffd83dbSDimitry Andric friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept; 1385ffd83dbSDimitry Andric friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept; 1395ffd83dbSDimitry Andric }; 1400b57cec5SDimitry Andric} 1410b57cec5SDimitry Andric*/ 1420b57cec5SDimitry Andric 143*0fca6ea1SDimitry Andric#include <__config> 144*0fca6ea1SDimitry Andric 145*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20 146349cc55cSDimitry Andric# include <__compare/common_comparison_category.h> 1471fd87a68SDimitry Andric# include <__compare/compare_partial_order_fallback.h> 1481fd87a68SDimitry Andric# include <__compare/compare_strong_order_fallback.h> 149349cc55cSDimitry Andric# include <__compare/compare_three_way.h> 150349cc55cSDimitry Andric# include <__compare/compare_three_way_result.h> 1511fd87a68SDimitry Andric# include <__compare/compare_weak_order_fallback.h> 152349cc55cSDimitry Andric# include <__compare/is_eq.h> 153349cc55cSDimitry Andric# include <__compare/ordering.h> 1544824e7fdSDimitry Andric# include <__compare/partial_order.h> 1554824e7fdSDimitry Andric# include <__compare/strong_order.h> 15606c3fb27SDimitry Andric# include <__compare/synth_three_way.h> 157349cc55cSDimitry Andric# include <__compare/three_way_comparable.h> 1584824e7fdSDimitry Andric# include <__compare/weak_order.h> 159*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 160*0fca6ea1SDimitry Andric 16104eeddc0SDimitry Andric#include <version> 1620b57cec5SDimitry Andric 1630eae32dcSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1640eae32dcSDimitry Andric# pragma GCC system_header 1650eae32dcSDimitry Andric#endif 1660eae32dcSDimitry Andric 167*0fca6ea1SDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17 168*0fca6ea1SDimitry Andric# include <cstddef> 169*0fca6ea1SDimitry Andric# include <cstdint> 170*0fca6ea1SDimitry Andric# include <limits> 171*0fca6ea1SDimitry Andric#endif 172*0fca6ea1SDimitry Andric 173bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 174*0fca6ea1SDimitry Andric# include <cmath> 175bdd1243dSDimitry Andric# include <type_traits> 176bdd1243dSDimitry Andric#endif 177bdd1243dSDimitry Andric 1780b57cec5SDimitry Andric#endif // _LIBCPP_COMPARE 179