10b57cec5SDimitry Andric// -*- C++ -*- 2*349cc55cSDimitry 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 38*349cc55cSDimitry Andric // [cmp.concept], concept three_way_comparable 39*349cc55cSDimitry Andric template<class T, class Cat = partial_ordering> 40*349cc55cSDimitry Andric concept three_way_comparable = see below; 41*349cc55cSDimitry Andric template<class T, class U, class Cat = partial_ordering> 42*349cc55cSDimitry Andric concept three_way_comparable_with = see below; 43*349cc55cSDimitry Andric 44*349cc55cSDimitry Andric // [cmp.result], result of three-way comparison 45*349cc55cSDimitry Andric template<class T, class U = T> struct compare_three_way_result; 46*349cc55cSDimitry Andric 47*349cc55cSDimitry Andric template<class T, class U = T> 48*349cc55cSDimitry Andric using compare_three_way_result_t = typename compare_three_way_result<T, U>::type; 49*349cc55cSDimitry Andric 50*349cc55cSDimitry Andric // [comparisons.three.way], class compare_three_way 51*349cc55cSDimitry Andric struct compare_three_way; // C++20 52*349cc55cSDimitry Andric 530b57cec5SDimitry Andric // [cmp.alg], comparison algorithms 540b57cec5SDimitry Andric template<class T> constexpr strong_ordering strong_order(const T& a, const T& b); 550b57cec5SDimitry Andric template<class T> constexpr weak_ordering weak_order(const T& a, const T& b); 560b57cec5SDimitry Andric template<class T> constexpr partial_ordering partial_order(const T& a, const T& b); 575ffd83dbSDimitry Andric 585ffd83dbSDimitry Andric // [cmp.partialord], Class partial_ordering 595ffd83dbSDimitry Andric class partial_ordering { 605ffd83dbSDimitry Andric public: 615ffd83dbSDimitry Andric // valid values 625ffd83dbSDimitry Andric static const partial_ordering less; 635ffd83dbSDimitry Andric static const partial_ordering equivalent; 645ffd83dbSDimitry Andric static const partial_ordering greater; 655ffd83dbSDimitry Andric static const partial_ordering unordered; 665ffd83dbSDimitry Andric 675ffd83dbSDimitry Andric // comparisons 685ffd83dbSDimitry Andric friend constexpr bool operator==(partial_ordering v, unspecified) noexcept; 695ffd83dbSDimitry Andric friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default; 705ffd83dbSDimitry Andric friend constexpr bool operator< (partial_ordering v, unspecified) noexcept; 715ffd83dbSDimitry Andric friend constexpr bool operator> (partial_ordering v, unspecified) noexcept; 725ffd83dbSDimitry Andric friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept; 735ffd83dbSDimitry Andric friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept; 745ffd83dbSDimitry Andric friend constexpr bool operator< (unspecified, partial_ordering v) noexcept; 755ffd83dbSDimitry Andric friend constexpr bool operator> (unspecified, partial_ordering v) noexcept; 765ffd83dbSDimitry Andric friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept; 775ffd83dbSDimitry Andric friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept; 785ffd83dbSDimitry Andric friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept; 795ffd83dbSDimitry Andric friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept; 805ffd83dbSDimitry Andric }; 815ffd83dbSDimitry Andric 825ffd83dbSDimitry Andric // [cmp.weakord], Class weak_ordering 835ffd83dbSDimitry Andric class weak_ordering { 845ffd83dbSDimitry Andric public: 855ffd83dbSDimitry Andric // valid values 865ffd83dbSDimitry Andric static const weak_ordering less; 875ffd83dbSDimitry Andric static const weak_ordering equivalent; 885ffd83dbSDimitry Andric static const weak_ordering greater; 895ffd83dbSDimitry Andric 905ffd83dbSDimitry Andric // conversions 915ffd83dbSDimitry Andric constexpr operator partial_ordering() const noexcept; 925ffd83dbSDimitry Andric 935ffd83dbSDimitry Andric // comparisons 945ffd83dbSDimitry Andric friend constexpr bool operator==(weak_ordering v, unspecified) noexcept; 955ffd83dbSDimitry Andric friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default; 965ffd83dbSDimitry Andric friend constexpr bool operator< (weak_ordering v, unspecified) noexcept; 975ffd83dbSDimitry Andric friend constexpr bool operator> (weak_ordering v, unspecified) noexcept; 985ffd83dbSDimitry Andric friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept; 995ffd83dbSDimitry Andric friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept; 1005ffd83dbSDimitry Andric friend constexpr bool operator< (unspecified, weak_ordering v) noexcept; 1015ffd83dbSDimitry Andric friend constexpr bool operator> (unspecified, weak_ordering v) noexcept; 1025ffd83dbSDimitry Andric friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept; 1035ffd83dbSDimitry Andric friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept; 1045ffd83dbSDimitry Andric friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept; 1055ffd83dbSDimitry Andric friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept; 1065ffd83dbSDimitry Andric }; 1075ffd83dbSDimitry Andric 1085ffd83dbSDimitry Andric // [cmp.strongord], Class strong_ordering 1095ffd83dbSDimitry Andric class strong_ordering { 1105ffd83dbSDimitry Andric public: 1115ffd83dbSDimitry Andric // valid values 1125ffd83dbSDimitry Andric static const strong_ordering less; 1135ffd83dbSDimitry Andric static const strong_ordering equal; 1145ffd83dbSDimitry Andric static const strong_ordering equivalent; 1155ffd83dbSDimitry Andric static const strong_ordering greater; 1165ffd83dbSDimitry Andric 1175ffd83dbSDimitry Andric // conversions 1185ffd83dbSDimitry Andric constexpr operator partial_ordering() const noexcept; 1195ffd83dbSDimitry Andric constexpr operator weak_ordering() const noexcept; 1205ffd83dbSDimitry Andric 1215ffd83dbSDimitry Andric // comparisons 1225ffd83dbSDimitry Andric friend constexpr bool operator==(strong_ordering v, unspecified) noexcept; 1235ffd83dbSDimitry Andric friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default; 1245ffd83dbSDimitry Andric friend constexpr bool operator< (strong_ordering v, unspecified) noexcept; 1255ffd83dbSDimitry Andric friend constexpr bool operator> (strong_ordering v, unspecified) noexcept; 1265ffd83dbSDimitry Andric friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept; 1275ffd83dbSDimitry Andric friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept; 1285ffd83dbSDimitry Andric friend constexpr bool operator< (unspecified, strong_ordering v) noexcept; 1295ffd83dbSDimitry Andric friend constexpr bool operator> (unspecified, strong_ordering v) noexcept; 1305ffd83dbSDimitry Andric friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept; 1315ffd83dbSDimitry Andric friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept; 1325ffd83dbSDimitry Andric friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept; 1335ffd83dbSDimitry Andric friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept; 1345ffd83dbSDimitry Andric }; 1350b57cec5SDimitry Andric} 1360b57cec5SDimitry Andric*/ 1370b57cec5SDimitry Andric 138*349cc55cSDimitry Andric#include <__compare/common_comparison_category.h> 139*349cc55cSDimitry Andric#include <__compare/compare_three_way.h> 140*349cc55cSDimitry Andric#include <__compare/compare_three_way_result.h> 141*349cc55cSDimitry Andric#include <__compare/is_eq.h> 142*349cc55cSDimitry Andric#include <__compare/ordering.h> 143*349cc55cSDimitry Andric#include <__compare/three_way_comparable.h> 1440b57cec5SDimitry Andric#include <__config> 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 1470b57cec5SDimitry Andric#pragma GCC system_header 1480b57cec5SDimitry Andric#endif 1490b57cec5SDimitry Andric 1500b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1510b57cec5SDimitry Andric 152*349cc55cSDimitry Andric#if _LIBCPP_STD_VER > 17 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andric// [cmp.alg], comparison algorithms 1550b57cec5SDimitry Andric// TODO: unimplemented 1560b57cec5SDimitry Andrictemplate<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs); 1570b57cec5SDimitry Andrictemplate<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs); 1580b57cec5SDimitry Andrictemplate<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs); 1590b57cec5SDimitry Andric 160*349cc55cSDimitry Andric#endif // _LIBCPP_STD_VER > 17 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andric#endif // _LIBCPP_COMPARE 165