[libc++] [P1614] Implement std::compare_three_way.
Differential Revision: https://reviews.llvm.org/D110735
NOKEYCHECK=True
GitOrigin-RevId: 3df094d31eac753687c7963738bb847e6d3794e9
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 3460f72..55834ab 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -102,6 +102,7 @@
__charconv/from_chars_result.h
__charconv/to_chars_result.h
__compare/common_comparison_category.h
+ __compare/compare_three_way.h
__compare/compare_three_way_result.h
__compare/is_eq.h
__compare/ordering.h
diff --git a/include/__compare/compare_three_way.h b/include/__compare/compare_three_way.h
new file mode 100644
index 0000000..492908a
--- /dev/null
+++ b/include/__compare/compare_three_way.h
@@ -0,0 +1,41 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
+#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
+
+#include <__config>
+#include <__compare/three_way_comparable.h>
+#include <__utility/forward.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR) && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+struct _LIBCPP_TEMPLATE_VIS compare_three_way
+{
+ template<class _T1, class _T2>
+ requires three_way_comparable_with<_T1, _T2>
+ constexpr _LIBCPP_HIDE_FROM_ABI
+ auto operator()(_T1&& __t, _T2&& __u) const
+ noexcept(noexcept(_VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u)))
+ { return _VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u); }
+
+ using is_transparent = void;
+};
+
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR) && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
diff --git a/include/compare b/include/compare
index ca1f574..ddb8313 100644
--- a/include/compare
+++ b/include/compare
@@ -47,6 +47,9 @@
template<class T, class U = T>
using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
+ // [comparisons.three.way], class compare_three_way
+ struct compare_three_way; // C++20
+
// [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);
@@ -133,6 +136,7 @@
*/
#include <__compare/common_comparison_category.h>
+#include <__compare/compare_three_way.h>
#include <__compare/compare_three_way_result.h>
#include <__compare/is_eq.h>
#include <__compare/ordering.h>
diff --git a/include/functional b/include/functional
index 3cff866..53a5f2b 100644
--- a/include/functional
+++ b/include/functional
@@ -135,6 +135,9 @@
bool operator()(const T& x, const T& y) const;
};
+// [comparisons.three.way], class compare_three_way
+struct compare_three_way;
+
template <class T> // <class T=void> in C++14
struct logical_and {
bool operator()(const T& x, const T& y) const;
@@ -488,6 +491,7 @@
*/
#include <__algorithm/search.h>
+#include <__compare/compare_three_way.h>
#include <__config>
#include <__debug>
#include <__functional/binary_function.h> // TODO: deprecate
diff --git a/include/module.modulemap b/include/module.modulemap
index 5abe243..d8049cb 100644
--- a/include/module.modulemap
+++ b/include/module.modulemap
@@ -372,6 +372,7 @@
module __compare {
module common_comparison_category { private header "__compare/common_comparison_category.h" }
+ module compare_three_way { private header "__compare/compare_three_way.h" }
module compare_three_way_result { private header "__compare/compare_three_way_result.h" }
module is_eq { private header "__compare/is_eq.h" }
module ordering { private header "__compare/ordering.h" }