xref: /freebsd/contrib/llvm-project/libcxx/include/compare (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
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
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
138349cc55cSDimitry Andric#include <__compare/common_comparison_category.h>
139349cc55cSDimitry Andric#include <__compare/compare_three_way.h>
140349cc55cSDimitry Andric#include <__compare/compare_three_way_result.h>
141349cc55cSDimitry Andric#include <__compare/is_eq.h>
142349cc55cSDimitry Andric#include <__compare/ordering.h>
1434824e7fdSDimitry Andric#include <__compare/partial_order.h>
1444824e7fdSDimitry Andric#include <__compare/strong_order.h>
145349cc55cSDimitry Andric#include <__compare/three_way_comparable.h>
1464824e7fdSDimitry Andric#include <__compare/weak_order.h>
1470b57cec5SDimitry Andric#include <__config>
148*04eeddc0SDimitry Andric#include <version>
1490b57cec5SDimitry Andric
1500eae32dcSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1510eae32dcSDimitry Andric#pragma GCC system_header
1520eae32dcSDimitry Andric#endif
1530eae32dcSDimitry Andric
1540b57cec5SDimitry Andric#endif // _LIBCPP_COMPARE
155