2018-04-07 05:37:23 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===-------------------------- compare -----------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-04-07 05:37:23 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_COMPARE
|
|
|
|
#define _LIBCPP_COMPARE
|
|
|
|
|
|
|
|
/*
|
|
|
|
compare synopsis
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
// [cmp.categories], comparison category types
|
|
|
|
class partial_ordering;
|
|
|
|
class weak_ordering;
|
|
|
|
class strong_ordering;
|
|
|
|
|
|
|
|
// named comparison functions
|
2021-07-29 13:34:31 +08:00
|
|
|
constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
|
|
|
|
constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
|
2018-04-07 05:37:23 +08:00
|
|
|
constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; }
|
|
|
|
constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
|
|
|
|
constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; }
|
|
|
|
constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
|
|
|
|
|
|
|
|
// [cmp.common], common comparison category type
|
|
|
|
template<class... Ts>
|
|
|
|
struct common_comparison_category {
|
|
|
|
using type = see below;
|
|
|
|
};
|
|
|
|
template<class... Ts>
|
|
|
|
using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
|
|
|
|
|
2021-09-05 11:16:18 +08:00
|
|
|
// [cmp.concept], concept three_way_comparable
|
|
|
|
template<class T, class Cat = partial_ordering>
|
|
|
|
concept three_way_comparable = see below;
|
|
|
|
template<class T, class U, class Cat = partial_ordering>
|
|
|
|
concept three_way_comparable_with = see below;
|
|
|
|
|
2021-07-29 12:03:01 +08:00
|
|
|
// [cmp.result], result of three-way comparison
|
|
|
|
template<class T, class U = T> struct compare_three_way_result;
|
|
|
|
|
|
|
|
template<class T, class U = T>
|
|
|
|
using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
|
|
|
|
|
2021-07-29 11:40:29 +08:00
|
|
|
// [comparisons.three.way], class compare_three_way
|
|
|
|
struct compare_three_way; // C++20
|
|
|
|
|
2018-04-07 05:37:23 +08:00
|
|
|
// [cmp.alg], comparison algorithms
|
|
|
|
template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
|
|
|
|
template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
|
|
|
|
template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
|
2020-06-18 22:17:57 +08:00
|
|
|
|
|
|
|
// [cmp.partialord], Class partial_ordering
|
|
|
|
class partial_ordering {
|
|
|
|
public:
|
|
|
|
// valid values
|
|
|
|
static const partial_ordering less;
|
|
|
|
static const partial_ordering equivalent;
|
|
|
|
static const partial_ordering greater;
|
|
|
|
static const partial_ordering unordered;
|
|
|
|
|
|
|
|
// comparisons
|
|
|
|
friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
|
|
|
|
friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
|
|
|
|
friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
// [cmp.weakord], Class weak_ordering
|
|
|
|
class weak_ordering {
|
|
|
|
public:
|
|
|
|
// valid values
|
|
|
|
static const weak_ordering less;
|
|
|
|
static const weak_ordering equivalent;
|
|
|
|
static const weak_ordering greater;
|
|
|
|
|
|
|
|
// conversions
|
|
|
|
constexpr operator partial_ordering() const noexcept;
|
|
|
|
|
|
|
|
// comparisons
|
|
|
|
friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
|
|
|
|
friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
|
|
|
|
friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
// [cmp.strongord], Class strong_ordering
|
|
|
|
class strong_ordering {
|
|
|
|
public:
|
|
|
|
// valid values
|
|
|
|
static const strong_ordering less;
|
|
|
|
static const strong_ordering equal;
|
|
|
|
static const strong_ordering equivalent;
|
|
|
|
static const strong_ordering greater;
|
|
|
|
|
|
|
|
// conversions
|
|
|
|
constexpr operator partial_ordering() const noexcept;
|
|
|
|
constexpr operator weak_ordering() const noexcept;
|
|
|
|
|
|
|
|
// comparisons
|
|
|
|
friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
|
|
|
|
friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
|
|
|
|
friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
|
|
|
|
friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
|
|
|
|
friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
|
|
|
|
};
|
2018-04-07 05:37:23 +08:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2021-07-29 10:05:46 +08:00
|
|
|
#include <__compare/common_comparison_category.h>
|
2021-07-29 11:40:29 +08:00
|
|
|
#include <__compare/compare_three_way.h>
|
2021-07-29 12:03:01 +08:00
|
|
|
#include <__compare/compare_three_way_result.h>
|
2021-09-27 12:48:39 +08:00
|
|
|
#include <__compare/is_eq.h>
|
2021-07-29 10:05:46 +08:00
|
|
|
#include <__compare/ordering.h>
|
2021-09-05 11:16:18 +08:00
|
|
|
#include <__compare/three_way_comparable.h>
|
2018-04-07 05:37:23 +08:00
|
|
|
#include <__config>
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
|
|
|
|
#pragma GCC system_header
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2021-04-13 04:55:05 +08:00
|
|
|
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
|
2018-04-07 05:37:23 +08:00
|
|
|
|
|
|
|
// [cmp.alg], comparison algorithms
|
|
|
|
// TODO: unimplemented
|
|
|
|
template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
|
|
|
|
template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
|
|
|
|
template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
|
|
|
|
|
2021-04-13 04:55:05 +08:00
|
|
|
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
|
2018-04-07 05:37:23 +08:00
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_COMPARE
|