[libcxx-commits] [libcxx] [libc++] <algorithm>: __is_callable checks whether the callable can be called with rvalue (PR #73451)
Nhat Nguyen via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 19 12:31:51 PST 2024
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,
=?utf-8?q?“Nhat?= <nhat7203 at gmail.com>,Nhat Nguyen
<nhat7203 at gmail.com>,Nhat Nguyen <nhat at berkeley.edu>,Nhat Nguyen
<nhat at berkeley.edu>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/73451 at github.com>
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/73451
>From 0b45818efdf587f75d93ef01a153f1f9c463912b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Sun, 26 Nov 2023 12:13:00 -0500
Subject: [PATCH 01/31] change static assert
---
libcxx/include/__algorithm/equal_range.h | 5 +++--
libcxx/include/__algorithm/includes.h | 5 +++--
libcxx/include/__algorithm/is_permutation.h | 5 +++--
libcxx/include/__algorithm/lower_bound.h | 5 +++--
libcxx/include/__algorithm/min_element.h | 6 +++---
libcxx/include/__algorithm/minmax_element.h | 5 +++--
.../include/__algorithm/partial_sort_copy.h | 5 +++--
.../random/random.uniform.real/test.cpp | 19 +++++++++++++++++++
8 files changed, 40 insertions(+), 15 deletions(-)
create mode 100644 libcxx/test/libcxx/random/random.uniform.real/test.cpp
diff --git a/libcxx/include/__algorithm/equal_range.h b/libcxx/include/__algorithm/equal_range.h
index dc1268a6ff110c..9528635730f751 100644
--- a/libcxx/include/__algorithm/equal_range.h
+++ b/libcxx/include/__algorithm/equal_range.h
@@ -60,8 +60,9 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
- "The comparator has to be callable");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
static_assert(is_copy_constructible<_ForwardIterator>::value,
"Iterator has to be copy constructible");
return std::__equal_range<_ClassicAlgPolicy>(
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 88253e2653d27a..9e20fe6174f337 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -45,8 +45,9 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_InputIterator2 __first2,
_InputIterator2 __last2,
_Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
- "Comparator has to be callable");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
return std::__includes(
std::move(__first1),
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 105a0732283c90..17aaf12ceeda2b 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -191,8 +191,9 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_BinaryPredicate __pred) {
- static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
diff --git a/libcxx/include/__algorithm/lower_bound.h b/libcxx/include/__algorithm/lower_bound.h
index 91c3bdaafd0cfd..399ebaa88e565d 100644
--- a/libcxx/include/__algorithm/lower_bound.h
+++ b/libcxx/include/__algorithm/lower_bound.h
@@ -49,8 +49,9 @@ _Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
- "The comparator has to be callable");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
auto __proj = std::__identity();
return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 45f3e85ef92d9f..3e8f1a31bced40 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -54,9 +54,9 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::min_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
- "The comparator has to be callable");
-
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 5bcaf8354d9ffb..49b62b87c6b260 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -85,8 +85,9 @@ pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
- "The comparator has to be callable");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index b9635c51d5fabe..a0b0525b4ee9e9 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -65,8 +65,9 @@ _RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
{
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
- "Comparator has to be callable");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
diff --git a/libcxx/test/libcxx/random/random.uniform.real/test.cpp b/libcxx/test/libcxx/random/random.uniform.real/test.cpp
new file mode 100644
index 00000000000000..bc84e362034ccd
--- /dev/null
+++ b/libcxx/test/libcxx/random/random.uniform.real/test.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<_RealType = double>
+// class uniform_real_distribution;
+
+// result_type must be floating type, int type is unsupported
+
+#include <random>
+
+// expected-error@*:* {{static assertion failed due to requirement '__libcpp_random_is_valid_realtype<int>::value': RealType must be a supported floating-point type}}
+struct test_random : public std::uniform_real_distribution<int> {};
>From f0925268b095ce6a4a1166cd444c511823a556c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Mon, 27 Nov 2023 22:56:45 -0500
Subject: [PATCH 02/31] remove strong static asserts
---
libcxx/include/__algorithm/includes.h | 3 +--
libcxx/include/__algorithm/is_permutation.h | 4 +---
libcxx/include/__algorithm/min_element.h | 3 +--
libcxx/include/__algorithm/minmax_element.h | 3 +--
libcxx/include/__algorithm/partial_sort_copy.h | 3 +--
5 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 9e20fe6174f337..54a3893a4ddafb 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -45,9 +45,8 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_InputIterator2 __first2,
_InputIterator2 __last2,
_Compare __comp) {
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
return std::__includes(
std::move(__first1),
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 17aaf12ceeda2b..2e74064b596c85 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -191,9 +191,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_BinaryPredicate __pred) {
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
- static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 3e8f1a31bced40..f7b3a05c5aef08 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -54,9 +54,8 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::min_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 49b62b87c6b260..49dcc5b17dc2a2 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -85,9 +85,8 @@ pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index a0b0525b4ee9e9..35337d41be3233 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -65,9 +65,8 @@ _RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
{
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
>From 16c779f0ce86a34c562c6662539a08260965b87a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 00:06:14 -0500
Subject: [PATCH 03/31] syntax fix
---
libcxx/include/__algorithm/is_permutation.h | 1 +
libcxx/include/__algorithm/min_element.h | 3 +--
libcxx/include/__algorithm/minmax_element.h | 3 +--
libcxx/include/__algorithm/partial_sort_copy.h | 3 +--
4 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 2e74064b596c85..105a0732283c90 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -192,6 +192,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
+ "The predicate has to be callable");
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index f7b3a05c5aef08..95b7628b45b3ba 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -54,8 +54,7 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::min_element requires a ForwardIterator");
- static_assert(
- __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 49dcc5b17dc2a2..790e5cfde4696a 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -85,8 +85,7 @@ pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
- static_assert(
- __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 35337d41be3233..3e50d5b56a175a 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -65,8 +65,7 @@ _RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
{
- static_assert(
- __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
>From 1ec11cdad3b4a11b81a076e6c038f49007586419 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 00:09:44 -0500
Subject: [PATCH 04/31] revert
---
libcxx/include/__algorithm/includes.h | 2 +-
libcxx/include/__algorithm/is_permutation.h | 2 +-
libcxx/include/__algorithm/min_element.h | 2 +-
libcxx/include/__algorithm/minmax.h | 108 ++++++++++++------
libcxx/include/__algorithm/minmax_element.h | 3 +-
.../include/__algorithm/partial_sort_copy.h | 2 +-
6 files changed, 76 insertions(+), 43 deletions(-)
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 54a3893a4ddafb..ce4372fc9c182e 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -66,4 +66,4 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_INCLUDES_H
+#endif // _LIBCPP___ALGORITHM_INCLUDES_H
\ No newline at end of file
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 105a0732283c90..a8e129a3ff314e 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -192,7 +192,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 95b7628b45b3ba..a86a29c89959a8 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -69,4 +69,4 @@ _LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
-#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
+#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
\ No newline at end of file
diff --git a/libcxx/include/__algorithm/minmax.h b/libcxx/include/__algorithm/minmax.h
index bdcf57b101e44e..da25e4ce6d5120 100644
--- a/libcxx/include/__algorithm/minmax.h
+++ b/libcxx/include/__algorithm/minmax.h
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#ifndef _LIBCPP___ALGORITHM_MINMAX_H
-#define _LIBCPP___ALGORITHM_MINMAX_H
+#ifndef _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
+#define _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
#include <__algorithm/comp.h>
-#include <__algorithm/minmax_element.h>
#include <__config>
#include <__functional/identity.h>
+#include <__functional/invoke.h>
+#include <__iterator/iterator_traits.h>
#include <__type_traits/is_callable.h>
#include <__utility/pair.h>
-#include <initializer_list>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -23,47 +23,79 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<const _Tp&, const _Tp&>
-minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
-{
- return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) :
- pair<const _Tp&, const _Tp&>(__a, __b);
-}
+template <class _Comp, class _Proj>
+class _MinmaxElementLessFunc {
+ _Comp& __comp_;
+ _Proj& __proj_;
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<const _Tp&, const _Tp&>
-minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
-{
- return std::minmax(__a, __b, __less<>());
-}
+public:
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
+ _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {}
-#ifndef _LIBCPP_CXX03_LANG
+ template <class _Iter>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+ bool operator()(_Iter& __it1, _Iter& __it2) {
+ return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2));
+ }
+};
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
- static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
- __identity __proj;
- auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
- return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
+template <class _Iter, class _Sent, class _Proj, class _Comp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
+ auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
+
+ pair<_Iter, _Iter> __result(__first, __first);
+ if (__first == __last || ++__first == __last)
+ return __result;
+
+ if (__less(__first, __result.first))
+ __result.first = __first;
+ else
+ __result.second = __first;
+
+ while (++__first != __last) {
+ _Iter __i = __first;
+ if (++__first == __last) {
+ if (__less(__i, __result.first))
+ __result.first = __i;
+ else if (!__less(__i, __result.second))
+ __result.second = __i;
+ return __result;
+ }
+
+ if (__less(__first, __i)) {
+ if (__less(__first, __result.first))
+ __result.first = __first;
+ if (!__less(__i, __result.second))
+ __result.second = __i;
+ } else {
+ if (__less(__i, __result.first))
+ __result.first = __i;
+ if (!__less(__first, __result.second))
+ __result.second = __first;
+ }
+ }
+
+ return __result;
}
-template<class _Tp>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Tp, _Tp>
-minmax(initializer_list<_Tp> __t)
-{
- return std::minmax(__t, __less<>());
+template <class _ForwardIterator, class _Compare>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+pair<_ForwardIterator, _ForwardIterator>
+minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
+ static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
+ "std::minmax_element requires a ForwardIterator");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
+ auto __proj = __identity();
+ return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
-#endif // _LIBCPP_CXX03_LANG
+template <class _ForwardIterator>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
+ return std::minmax_element(__first, __last, __less<>());
+}
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_MINMAX_H
+#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
\ No newline at end of file
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 790e5cfde4696a..49dcc5b17dc2a2 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -85,7 +85,8 @@ pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 3e50d5b56a175a..d82a8814a189ac 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -83,4 +83,4 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
+#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
\ No newline at end of file
>From a42a3a6aa63f72aa32d3bed14536197002f29cba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 00:15:17 -0500
Subject: [PATCH 05/31] revert
---
libcxx/include/__algorithm/includes.h | 4 +-
libcxx/include/__algorithm/is_permutation.h | 4 +-
libcxx/include/__algorithm/min_element.h | 4 +-
libcxx/include/__algorithm/minmax.h | 106 ++++++------------
libcxx/include/__algorithm/minmax_element.h | 6 +-
.../include/__algorithm/partial_sort_copy.h | 7 +-
6 files changed, 51 insertions(+), 80 deletions(-)
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index ce4372fc9c182e..86bb86b3f47bab 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -45,8 +45,8 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_InputIterator2 __first2,
_InputIterator2 __last2,
_Compare __comp) {
- static_assert(
- __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
+ "Comparator has to be callable");
return std::__includes(
std::move(__first1),
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index a8e129a3ff314e..4539ce9724c8b1 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -192,7 +192,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
@@ -240,4 +240,4 @@ _LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
-#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
+#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
\ No newline at end of file
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index a86a29c89959a8..59dd7ba4b14fa3 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -54,7 +54,9 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::min_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
+ "The comparator has to be callable");
+
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
diff --git a/libcxx/include/__algorithm/minmax.h b/libcxx/include/__algorithm/minmax.h
index da25e4ce6d5120..20107efd1f3381 100644
--- a/libcxx/include/__algorithm/minmax.h
+++ b/libcxx/include/__algorithm/minmax.h
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#ifndef _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
-#define _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
+#ifndef _LIBCPP___ALGORITHM_MINMAX_H
+#define _LIBCPP___ALGORITHM_MINMAX_H
#include <__algorithm/comp.h>
+#include <__algorithm/minmax_element.h>
#include <__config>
#include <__functional/identity.h>
-#include <__functional/invoke.h>
-#include <__iterator/iterator_traits.h>
#include <__type_traits/is_callable.h>
#include <__utility/pair.h>
+#include <initializer_list>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -23,79 +23,47 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _Comp, class _Proj>
-class _MinmaxElementLessFunc {
- _Comp& __comp_;
- _Proj& __proj_;
-
-public:
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
- _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {}
-
- template <class _Iter>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
- bool operator()(_Iter& __it1, _Iter& __it2) {
- return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2));
- }
-};
-
-template <class _Iter, class _Sent, class _Proj, class _Comp>
+template<class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
- auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
-
- pair<_Iter, _Iter> __result(__first, __first);
- if (__first == __last || ++__first == __last)
- return __result;
-
- if (__less(__first, __result.first))
- __result.first = __first;
- else
- __result.second = __first;
+pair<const _Tp&, const _Tp&>
+minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
+{
+ return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) :
+ pair<const _Tp&, const _Tp&>(__a, __b);
+}
- while (++__first != __last) {
- _Iter __i = __first;
- if (++__first == __last) {
- if (__less(__i, __result.first))
- __result.first = __i;
- else if (!__less(__i, __result.second))
- __result.second = __i;
- return __result;
- }
+template<class _Tp>
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+pair<const _Tp&, const _Tp&>
+minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
+{
+ return std::minmax(__a, __b, __less<>());
+}
- if (__less(__first, __i)) {
- if (__less(__first, __result.first))
- __result.first = __first;
- if (!__less(__i, __result.second))
- __result.second = __i;
- } else {
- if (__less(__i, __result.first))
- __result.first = __i;
- if (!__less(__first, __result.second))
- __result.second = __first;
- }
- }
+#ifndef _LIBCPP_CXX03_LANG
- return __result;
+template<class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
+ static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
+ __identity __proj;
+ auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
+ return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
}
-template <class _ForwardIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_ForwardIterator, _ForwardIterator>
-minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
- static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
- "std::minmax_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
- auto __proj = __identity();
- return std::__minmax_element_impl(__first, __last, __comp, __proj);
+template<class _Tp>
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+pair<_Tp, _Tp>
+minmax(initializer_list<_Tp> __t)
+{
+ return std::minmax(__t, __less<>());
}
-template <class _ForwardIterator>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
- return std::minmax_element(__first, __last, __less<>());
-}
+#endif // _LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_MINMAX_H
\ No newline at end of file
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 49dcc5b17dc2a2..ad450fb0ef0965 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -85,8 +85,8 @@ pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
- static_assert(
- __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
+ "The comparator has to be callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
@@ -99,4 +99,4 @@ pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
+#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
\ No newline at end of file
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index d82a8814a189ac..1e9404c9f76917 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -60,12 +60,13 @@ __partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
{
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
+ "Comparator has to be callable");
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
@@ -73,7 +74,7 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
>From 8772446b7184967cac3ff4267ee17d97f9ae54cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 00:21:23 -0500
Subject: [PATCH 06/31] revert
---
libcxx/include/__algorithm/equal_range.h | 5 ++---
libcxx/include/__algorithm/includes.h | 2 +-
libcxx/include/__algorithm/is_permutation.h | 2 +-
libcxx/include/__algorithm/lower_bound.h | 5 ++---
libcxx/include/__algorithm/min_element.h | 2 +-
libcxx/include/__algorithm/minmax.h | 8 ++++----
libcxx/include/__algorithm/minmax_element.h | 2 +-
libcxx/include/__algorithm/partial_sort_copy.h | 6 +++---
8 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/libcxx/include/__algorithm/equal_range.h b/libcxx/include/__algorithm/equal_range.h
index 9528635730f751..dc1268a6ff110c 100644
--- a/libcxx/include/__algorithm/equal_range.h
+++ b/libcxx/include/__algorithm/equal_range.h
@@ -60,9 +60,8 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
- static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
+ "The comparator has to be callable");
static_assert(is_copy_constructible<_ForwardIterator>::value,
"Iterator has to be copy constructible");
return std::__equal_range<_ClassicAlgPolicy>(
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 86bb86b3f47bab..88253e2653d27a 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -66,4 +66,4 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_INCLUDES_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_INCLUDES_H
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 4539ce9724c8b1..105a0732283c90 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -240,4 +240,4 @@ _LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
-#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
diff --git a/libcxx/include/__algorithm/lower_bound.h b/libcxx/include/__algorithm/lower_bound.h
index 399ebaa88e565d..91c3bdaafd0cfd 100644
--- a/libcxx/include/__algorithm/lower_bound.h
+++ b/libcxx/include/__algorithm/lower_bound.h
@@ -49,9 +49,8 @@ _Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
- static_assert(
- __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
+ "The comparator has to be callable");
auto __proj = std::__identity();
return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 59dd7ba4b14fa3..45f3e85ef92d9f 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -71,4 +71,4 @@ _LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
-#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
diff --git a/libcxx/include/__algorithm/minmax.h b/libcxx/include/__algorithm/minmax.h
index 20107efd1f3381..bdcf57b101e44e 100644
--- a/libcxx/include/__algorithm/minmax.h
+++ b/libcxx/include/__algorithm/minmax.h
@@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<const _Tp&, const _Tp&>
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
{
@@ -35,7 +35,7 @@ minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<const _Tp&, const _Tp&>
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
{
@@ -55,7 +55,7 @@ pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<_Tp, _Tp>
minmax(initializer_list<_Tp> __t)
{
@@ -66,4 +66,4 @@ minmax(initializer_list<_Tp> __t)
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_MINMAX_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_MINMAX_H
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index ad450fb0ef0965..5bcaf8354d9ffb 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -99,4 +99,4 @@ pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 1e9404c9f76917..b9635c51d5fabe 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -60,7 +60,7 @@ __partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
_RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
@@ -74,7 +74,7 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
_RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
@@ -84,4 +84,4 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
>From f94c5aa78c25729d3795d16c61fc634aaf86e1a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 00:33:09 -0500
Subject: [PATCH 07/31] const callable add
---
libcxx/include/__algorithm/equal_range.h | 7 +++----
libcxx/include/__algorithm/includes.h | 2 ++
libcxx/include/__algorithm/is_permutation.h | 4 ++++
libcxx/include/__algorithm/lower_bound.h | 2 ++
libcxx/include/__algorithm/min_element.h | 2 ++
libcxx/include/__algorithm/minmax.h | 1 +
libcxx/include/__algorithm/minmax_element.h | 3 +++
libcxx/include/__algorithm/partial_sort_copy.h | 3 +++
libcxx/include/__algorithm/search.h | 4 +++-
libcxx/include/__algorithm/search_n.h | 3 +++
10 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__algorithm/equal_range.h b/libcxx/include/__algorithm/equal_range.h
index dc1268a6ff110c..aa5f93532741ef 100644
--- a/libcxx/include/__algorithm/equal_range.h
+++ b/libcxx/include/__algorithm/equal_range.h
@@ -60,10 +60,9 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
- "The comparator has to be callable");
- static_assert(is_copy_constructible<_ForwardIterator>::value,
- "Iterator has to be copy constructible");
+ static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
return std::__equal_range<_ClassicAlgPolicy>(
std::move(__first),
std::move(__last),
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 88253e2653d27a..ef1bfd491375ad 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -47,6 +47,8 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_Compare __comp) {
static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
"Comparator has to be callable");
+ static_assert(__is_callable<_Compare const&, decltype(*__first1), decltype(*__first2)>::value,
+ "Comparator has to be const-callable");
return std::__includes(
std::move(__first1),
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 105a0732283c90..c58afb622db674 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -193,6 +193,8 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be callable");
+ static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
+ "The predicate has to be const-callable");
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
@@ -228,6 +230,8 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt
_ForwardIterator2 __last2, _BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be callable");
+ static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
+ "The predicate has to be const-callable");
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
diff --git a/libcxx/include/__algorithm/lower_bound.h b/libcxx/include/__algorithm/lower_bound.h
index 91c3bdaafd0cfd..9063e36b1b7955 100644
--- a/libcxx/include/__algorithm/lower_bound.h
+++ b/libcxx/include/__algorithm/lower_bound.h
@@ -51,6 +51,8 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
"The comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
auto __proj = std::__identity();
return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 45f3e85ef92d9f..67f36027bc7741 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -56,6 +56,8 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
"std::min_element requires a ForwardIterator");
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be callable");
+ static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__first)>::value,
+ "The comparator has to be const-callable");
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
diff --git a/libcxx/include/__algorithm/minmax.h b/libcxx/include/__algorithm/minmax.h
index bdcf57b101e44e..9d03ff6a09a0db 100644
--- a/libcxx/include/__algorithm/minmax.h
+++ b/libcxx/include/__algorithm/minmax.h
@@ -48,6 +48,7 @@ template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare const&, _Tp, _Tp>::value, "The comparator has to be callable");
__identity __proj;
auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 5bcaf8354d9ffb..5191c73d86c93e 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -87,6 +87,9 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __com
"std::minmax_element requires a ForwardIterator");
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be callable");
+
+ static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__first)>::value,
+ "The comparator has to be const-callable");
auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj);
}
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index b9635c51d5fabe..1d0f1db989f3fb 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -68,6 +68,9 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
"Comparator has to be callable");
+ static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
+ "Comparator has to be callable");
+
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
return __result.second;
diff --git a/libcxx/include/__algorithm/search.h b/libcxx/include/__algorithm/search.h
index 5882a04808ba57..6d73d35aff654d 100644
--- a/libcxx/include/__algorithm/search.h
+++ b/libcxx/include/__algorithm/search.h
@@ -175,8 +175,10 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_C
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred) {
- static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
+ static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"BinaryPredicate has to be callable");
+ static_assert(__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value,
+ "BinaryPredicate has to be const-callable");
auto __proj = __identity();
return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first;
}
diff --git a/libcxx/include/__algorithm/search_n.h b/libcxx/include/__algorithm/search_n.h
index 7e3ddf48a2b6c0..b4306538761363 100644
--- a/libcxx/include/__algorithm/search_n.h
+++ b/libcxx/include/__algorithm/search_n.h
@@ -167,6 +167,9 @@ _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value,
"BinaryPredicate has to be callable");
+
+ static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first), const _Tp&>::value,
+ "BinaryPredicate has to be const-callable");
auto __proj = __identity();
return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first;
}
>From 4b90b5df30c97dff40a6f07a416fff35e669574d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 00:47:15 -0500
Subject: [PATCH 08/31] add unit test
---
.../libcxx/algorithms/const_callable.veriry.cpp | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
diff --git a/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp b/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
new file mode 100644
index 00000000000000..dfdeb25544968e
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
@@ -0,0 +1,16 @@
+#include <algorithm>
+
+struct ConstUncallable {
+ void operator()(int, int) const& = delete;
+ void operator()(int , int) & { return; }
+};
+
+struct NonConstUncallable {
+ void operator()(int, int) const& { return; }
+ void operator()(int, int) & = delete;
+};
+
+void test() {
+ std::minmax({42, 0, -42}, ConstUncallable{});
+ //expected-error-re@*:* {{static_assert(__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable")}}
+}
\ No newline at end of file
>From 7019fea3cdb91905c16208e09fbddb4fddf5dbe3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 5 Dec 2023 01:15:32 -0500
Subject: [PATCH 09/31] clang format
---
libcxx/test/libcxx/algorithms/const_callable.veriry.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp b/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
index dfdeb25544968e..b14e5ec1ad4852 100644
--- a/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
+++ b/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
@@ -2,11 +2,11 @@
struct ConstUncallable {
void operator()(int, int) const& = delete;
- void operator()(int , int) & { return; }
+ void operator()(int, int) & { return; }
};
struct NonConstUncallable {
- void operator()(int, int) const& { return; }
+ void operator()(int, int) const& { return; }
void operator()(int, int) & = delete;
};
>From 5bef83ad557d534bc78964489409adcea4117c10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Thu, 14 Dec 2023 11:08:44 -0800
Subject: [PATCH 10/31] add license and syntax fix
---
.../test/libcxx/algorithms/const_callable.veriry.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp b/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
index b14e5ec1ad4852..5085bd1eef135e 100644
--- a/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
+++ b/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
#include <algorithm>
struct ConstUncallable {
@@ -13,4 +21,4 @@ struct NonConstUncallable {
void test() {
std::minmax({42, 0, -42}, ConstUncallable{});
//expected-error-re@*:* {{static_assert(__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable")}}
-}
\ No newline at end of file
+}
>From 4f3376303b2489f94b2b958d22e62a431dc869a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Thu, 14 Dec 2023 11:10:16 -0800
Subject: [PATCH 11/31] change file name
---
.../{const_callable.veriry.cpp => const_callable.verify.cpp} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename libcxx/test/libcxx/algorithms/{const_callable.veriry.cpp => const_callable.verify.cpp} (100%)
diff --git a/libcxx/test/libcxx/algorithms/const_callable.veriry.cpp b/libcxx/test/libcxx/algorithms/const_callable.verify.cpp
similarity index 100%
rename from libcxx/test/libcxx/algorithms/const_callable.veriry.cpp
rename to libcxx/test/libcxx/algorithms/const_callable.verify.cpp
>From 4b1bb73e5389d739193cea25d327476bb9e85197 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Thu, 14 Dec 2023 11:23:28 -0800
Subject: [PATCH 12/31] remove wrongly-created files
---
.../random/random.uniform.real/test.cpp | 19 -------------------
1 file changed, 19 deletions(-)
delete mode 100644 libcxx/test/libcxx/random/random.uniform.real/test.cpp
diff --git a/libcxx/test/libcxx/random/random.uniform.real/test.cpp b/libcxx/test/libcxx/random/random.uniform.real/test.cpp
deleted file mode 100644
index bc84e362034ccd..00000000000000
--- a/libcxx/test/libcxx/random/random.uniform.real/test.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-// <random>
-
-// template<_RealType = double>
-// class uniform_real_distribution;
-
-// result_type must be floating type, int type is unsupported
-
-#include <random>
-
-// expected-error@*:* {{static assertion failed due to requirement '__libcpp_random_is_valid_realtype<int>::value': RealType must be a supported floating-point type}}
-struct test_random : public std::uniform_real_distribution<int> {};
>From 2aa19a3f7edd010e3577ed442312c9c4e49bbb8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Thu, 14 Dec 2023 14:00:16 -0800
Subject: [PATCH 13/31] add test to pass all
---
.../libcxx/algorithms/const_callable.pass.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 libcxx/test/libcxx/algorithms/const_callable.pass.cpp
diff --git a/libcxx/test/libcxx/algorithms/const_callable.pass.cpp b/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
new file mode 100644
index 00000000000000..9c3cb87fd4e859
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <algorithm>
+
+struct RvalueRefUncallable {
+ bool operator()(int, int) && = delete;
+ bool operator()(int, int) const &{ return true; }
+};
+
+int main(int, char**){
+ assert(std::minmax({42, 0, -42}, RvalueRefUncallable{}).first == true);
+}
\ No newline at end of file
>From 1e70b10cbaa3c029a818e8314ebc301cebeb4b1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Thu, 14 Dec 2023 14:18:04 -0800
Subject: [PATCH 14/31] new line eof
---
libcxx/test/libcxx/algorithms/const_callable.pass.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libcxx/test/libcxx/algorithms/const_callable.pass.cpp b/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
index 9c3cb87fd4e859..b8d4d4f28ad9b3 100644
--- a/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
@@ -13,6 +13,4 @@ struct RvalueRefUncallable {
bool operator()(int, int) const &{ return true; }
};
-int main(int, char**){
- assert(std::minmax({42, 0, -42}, RvalueRefUncallable{}).first == true);
-}
\ No newline at end of file
+int main(int, char**) { assert(std::minmax({42, 0, -42}, RvalueRefUncallable{}).first == true); }
>From 9c225a97af9df4ddd5be18447d68bb509f83f22c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Fri, 15 Dec 2023 00:11:18 -0800
Subject: [PATCH 15/31] code formatter
---
libcxx/test/libcxx/algorithms/const_callable.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/libcxx/algorithms/const_callable.pass.cpp b/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
index b8d4d4f28ad9b3..9c8bdb17b93c41 100644
--- a/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/const_callable.pass.cpp
@@ -10,7 +10,7 @@
struct RvalueRefUncallable {
bool operator()(int, int) && = delete;
- bool operator()(int, int) const &{ return true; }
+ bool operator()(int, int) const& { return true; }
};
int main(int, char**) { assert(std::minmax({42, 0, -42}, RvalueRefUncallable{}).first == true); }
>From 8946eaa8601eeb6f09c559fa242f4e0a0db59eb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Fri, 15 Dec 2023 14:52:00 -0800
Subject: [PATCH 16/31] some syntax fix
---
libcxx/include/__algorithm/search.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__algorithm/search.h b/libcxx/include/__algorithm/search.h
index 6d73d35aff654d..ba1d49a5a9ff2d 100644
--- a/libcxx/include/__algorithm/search.h
+++ b/libcxx/include/__algorithm/search.h
@@ -175,9 +175,9 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_C
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred) {
- static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
+ static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
"BinaryPredicate has to be callable");
- static_assert(__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value,
+ static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first), decltype(*__first2)>::value,
"BinaryPredicate has to be const-callable");
auto __proj = __identity();
return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first;
>From e92e0f6ce258a7b1e884522efc271cf233e163d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Fri, 15 Dec 2023 14:54:05 -0800
Subject: [PATCH 17/31] syntax fix
---
libcxx/include/__algorithm/equal_range.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__algorithm/equal_range.h b/libcxx/include/__algorithm/equal_range.h
index aa5f93532741ef..9b09ad6146502c 100644
--- a/libcxx/include/__algorithm/equal_range.h
+++ b/libcxx/include/__algorithm/equal_range.h
@@ -60,7 +60,7 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(
__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
return std::__equal_range<_ClassicAlgPolicy>(
>From 55c406db1728f21be7fecf67198703898748095c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Fri, 15 Dec 2023 15:05:32 -0800
Subject: [PATCH 18/31] syntax fix
---
libcxx/include/__algorithm/search.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__algorithm/search.h b/libcxx/include/__algorithm/search.h
index ba1d49a5a9ff2d..6544c568033a5f 100644
--- a/libcxx/include/__algorithm/search.h
+++ b/libcxx/include/__algorithm/search.h
@@ -177,7 +177,7 @@ _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
"BinaryPredicate has to be callable");
- static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first), decltype(*__first2)>::value,
+ static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"BinaryPredicate has to be const-callable");
auto __proj = __identity();
return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first;
>From c4b16d2265c7b73d739a205dd8c490e9c01884ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 13:16:02 -0500
Subject: [PATCH 19/31] fix clang-format from upstream merge
---
libcxx/include/__algorithm/equal_range.h | 1 -
libcxx/include/__algorithm/includes.h | 1 +
libcxx/include/__algorithm/is_permutation.h | 3 +--
libcxx/include/__algorithm/min_element.h | 1 -
libcxx/include/__algorithm/minmax_element.h | 5 ++---
libcxx/include/__algorithm/partial_sort_copy.h | 2 --
libcxx/include/__algorithm/search_n.h | 5 ++---
7 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/libcxx/include/__algorithm/equal_range.h b/libcxx/include/__algorithm/equal_range.h
index 7a29da6a804510..7ebc0f5315c63b 100644
--- a/libcxx/include/__algorithm/equal_range.h
+++ b/libcxx/include/__algorithm/equal_range.h
@@ -66,7 +66,6 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
static_assert(
__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
-
static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
return std::__equal_range<_ClassicAlgPolicy>(
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 8c60fdbba9296c..ba15599456f4fb 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -56,6 +56,7 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_Compare __comp) {
static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
"Comparator has to be callable");
+
static_assert(__is_callable<_Compare const&, decltype(*__first1), decltype(*__first2)>::value,
"Comparator has to be const-callable");
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index e2677daf05ad7b..ecb518e2a834c2 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -289,8 +289,7 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_ForwardIterator2 __last2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
-
- "The predicate has to be callable");
+ "The predicate has to be callable");
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be const-callable");
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 3540071144dd06..ec660d46dbb8f8 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -59,7 +59,6 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be const-callable");
-
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
}
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index e3eebe427dca16..46dbbd313eb1c5 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -84,9 +84,8 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __com
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
- "The comparator has to be callable");
-
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be const-callable");
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 03e79e48341c42..0210faecc518d0 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -78,8 +78,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
_Compare __comp) {
static_assert(
__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
-
-
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
"Comparator has to be callable");
diff --git a/libcxx/include/__algorithm/search_n.h b/libcxx/include/__algorithm/search_n.h
index a29f3c58cf7248..72a7e69bb41203 100644
--- a/libcxx/include/__algorithm/search_n.h
+++ b/libcxx/include/__algorithm/search_n.h
@@ -141,9 +141,8 @@ _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last,
_Size __count,
const _Tp& __value,
_BinaryPredicate __pred) {
- static_assert(__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value,
- "BinaryPredicate has to be callable");
-
+ static_assert(
+ __is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable");
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first), const _Tp&>::value,
"BinaryPredicate has to be const-callable");
>From df9edb335544ff141bf22d7e63f8709633fd2eca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 13:23:11 -0500
Subject: [PATCH 20/31] support const& qualifier
---
libcxx/src/regex.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libcxx/src/regex.cpp b/libcxx/src/regex.cpp
index 9dc0c698541c8f..dccfc84f1feb81 100644
--- a/libcxx/src/regex.cpp
+++ b/libcxx/src/regex.cpp
@@ -323,8 +323,10 @@ const classnames ClassNames[] = {
{"xdigit", ctype_base::xdigit}};
struct use_strcmp {
- bool operator()(const collationnames& x, const char* y) { return strcmp(x.elem_, y) < 0; }
- bool operator()(const classnames& x, const char* y) { return strcmp(x.elem_, y) < 0; }
+ bool operator()(const collationnames& x, const char* y) & { return strcmp(x.elem_, y) < 0; }
+ bool operator()(const classnames& x, const char* y) & { return strcmp(x.elem_, y) < 0; }
+ bool operator()(const collationnames& x, const char* y) const& { return strcmp(x.elem_, y) < 0; }
+ bool operator()(const classnames& x, const char* y) const& { return strcmp(x.elem_, y) < 0; }
};
} // namespace
>From d7e866105043e6e308b2c72992899afd2cf0926b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 13:45:12 -0500
Subject: [PATCH 21/31] add const& qualifier
---
...st_against_cpp20_hostile_iterators.compile.pass.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libcxx/test/libcxx/algorithms/robust_against_cpp20_hostile_iterators.compile.pass.cpp b/libcxx/test/libcxx/algorithms/robust_against_cpp20_hostile_iterators.compile.pass.cpp
index 78a58634bc2163..aa8a9b5964ba55 100644
--- a/libcxx/test/libcxx/algorithms/robust_against_cpp20_hostile_iterators.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/robust_against_cpp20_hostile_iterators.compile.pass.cpp
@@ -72,9 +72,13 @@ struct Cpp20HostileIterator
};
struct Pred {
- bool operator()(int, int) { return false; }
- bool operator()(int) { return false; }
- int operator()() { return 0; }
+ bool operator()(int, int) & { return false; }
+ bool operator()(int) & { return false; }
+ int operator()() & { return 0; }
+
+ bool operator()(int, int) const& { return false; }
+ bool operator()(int) const& { return false; }
+ int operator()() const& { return 0; }
};
void test() {
>From 608f995623ff86943dfa7cd458a7ff5a10aeb192 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 14:38:59 -0500
Subject: [PATCH 22/31] clang-format
---
libcxx/include/__algorithm/includes.h | 6 ++----
libcxx/include/__algorithm/is_permutation.h | 1 -
libcxx/include/__algorithm/lower_bound.h | 7 +++----
libcxx/include/__algorithm/min_element.h | 8 ++++----
libcxx/include/__algorithm/minmax.h | 10 +++++-----
libcxx/include/__algorithm/minmax_element.h | 5 ++---
6 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index ba15599456f4fb..4a82cc7a225224 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -54,13 +54,11 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_InputIterator2 __first2,
_InputIterator2 __last2,
_Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
- "Comparator has to be callable");
-
+ static_assert(
+ __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
static_assert(__is_callable<_Compare const&, decltype(*__first1), decltype(*__first2)>::value,
"Comparator has to be const-callable");
-
return std::__includes(
std::move(__first1),
std::move(__last1),
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index ecb518e2a834c2..1e62c4f16d1029 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -293,7 +293,6 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be const-callable");
-
return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1),
std::move(__last1),
diff --git a/libcxx/include/__algorithm/lower_bound.h b/libcxx/include/__algorithm/lower_bound.h
index cbb9db3c9ce41f..20fa592d7af3c8 100644
--- a/libcxx/include/__algorithm/lower_bound.h
+++ b/libcxx/include/__algorithm/lower_bound.h
@@ -48,10 +48,9 @@ __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp,
template <class _ForwardIterator, class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
- static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
- "The comparator has to be callable");
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
+ static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(
__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable");
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index ec660d46dbb8f8..66fd7c2c56b201 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -52,10 +52,10 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
- static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
- "std::min_element requires a ForwardIterator");
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
- "The comparator has to be callable");
+ static_assert(
+ __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be const-callable");
diff --git a/libcxx/include/__algorithm/minmax.h b/libcxx/include/__algorithm/minmax.h
index 14464eb6c7ab02..96f11a165468a4 100644
--- a/libcxx/include/__algorithm/minmax.h
+++ b/libcxx/include/__algorithm/minmax.h
@@ -40,11 +40,11 @@ minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
- static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
- static_assert(__is_callable<_Compare const&, _Tp, _Tp>::value, "The comparator has to be callable");
- __identity __proj;
- auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
- return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
+ static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
+ static_assert(__is_callable<_Compare const&, _Tp, _Tp>::value, "The comparator has to be callable");
+ __identity __proj;
+ auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
+ return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
}
diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h
index 46dbbd313eb1c5..90f6d7afb733ba 100644
--- a/libcxx/include/__algorithm/minmax_element.h
+++ b/libcxx/include/__algorithm/minmax_element.h
@@ -81,9 +81,8 @@ __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj)
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
-
- static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
- "std::minmax_element requires a ForwardIterator");
+ static_assert(
+ __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator");
static_assert(
__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__first)>::value,
>From 61bfc22f8870137a9f8679f9397b306725028c8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 14:47:54 -0500
Subject: [PATCH 23/31] clang-format
---
libcxx/include/__algorithm/includes.h | 12 ++++++------
libcxx/include/__algorithm/is_permutation.h | 2 +-
libcxx/include/__algorithm/min_element.h | 3 +--
libcxx/include/__algorithm/minmax.h | 7 +++----
libcxx/include/__algorithm/partial_sort_copy.h | 10 ++++++++--
libcxx/include/__algorithm/search_n.h | 7 ++-----
6 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/libcxx/include/__algorithm/includes.h b/libcxx/include/__algorithm/includes.h
index 4a82cc7a225224..c71606fe40ff9d 100644
--- a/libcxx/include/__algorithm/includes.h
+++ b/libcxx/include/__algorithm/includes.h
@@ -48,12 +48,12 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes(
template <class _InputIterator1, class _InputIterator2, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes(
- _InputIterator1 __first1,
- _InputIterator1 __last1,
- _InputIterator2 __first2,
- _InputIterator2 __last2,
- _Compare __comp) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+includes(_InputIterator1 __first1,
+ _InputIterator1 __last1,
+ _InputIterator2 __first2,
+ _InputIterator2 __last2,
+ _Compare __comp) {
static_assert(
__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
static_assert(__is_callable<_Compare const&, decltype(*__first1), decltype(*__first2)>::value,
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 1e62c4f16d1029..530a32876325e9 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -289,7 +289,7 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_ForwardIterator2 __last2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be const-callable");
diff --git a/libcxx/include/__algorithm/min_element.h b/libcxx/include/__algorithm/min_element.h
index 66fd7c2c56b201..3612e8c64b683e 100644
--- a/libcxx/include/__algorithm/min_element.h
+++ b/libcxx/include/__algorithm/min_element.h
@@ -50,8 +50,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
-{
+min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(
__has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
static_assert(
diff --git a/libcxx/include/__algorithm/minmax.h b/libcxx/include/__algorithm/minmax.h
index 96f11a165468a4..71e2598efeb4ae 100644
--- a/libcxx/include/__algorithm/minmax.h
+++ b/libcxx/include/__algorithm/minmax.h
@@ -37,15 +37,14 @@ minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __
#ifndef _LIBCPP_CXX03_LANG
-template<class _Tp, class _Compare>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
-pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
+template <class _Tp, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
+minmax(initializer_list<_Tp> __t, _Compare __comp) {
static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
static_assert(__is_callable<_Compare const&, _Tp, _Tp>::value, "The comparator has to be callable");
__identity __proj;
auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
-
}
template <class _Tp>
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 0210faecc518d0..d21054639b1ec3 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -81,8 +81,14 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
"Comparator has to be callable");
- auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
- static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
+ auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
+ __first,
+ __last,
+ __result_first,
+ __result_last,
+ static_cast<__comp_ref_type<_Compare> >(__comp),
+ __identity(),
+ __identity());
return __result.second;
}
diff --git a/libcxx/include/__algorithm/search_n.h b/libcxx/include/__algorithm/search_n.h
index 72a7e69bb41203..e6946d14b16b3a 100644
--- a/libcxx/include/__algorithm/search_n.h
+++ b/libcxx/include/__algorithm/search_n.h
@@ -136,11 +136,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __searc
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last,
- _Size __count,
- const _Tp& __value,
- _BinaryPredicate __pred) {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(
+ _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) {
static_assert(
__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable");
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first), const _Tp&>::value,
>From 2ee86733123f942ff822ca9e02974f3c0f2793c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 14:54:19 -0500
Subject: [PATCH 24/31] clang-format
---
libcxx/include/__algorithm/is_permutation.h | 4 ++--
libcxx/include/__algorithm/partial_sort_copy.h | 14 +++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index 530a32876325e9..206dad7bace1ae 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -250,7 +250,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be const-callable");
@@ -289,7 +289,7 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
_ForwardIterator2 __last2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
- "The predicate has to be callable");
+ "The predicate has to be callable");
static_assert(__is_callable<_BinaryPredicate const&, decltype(*__first1), decltype(*__first2)>::value,
"The predicate has to be const-callable");
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index d21054639b1ec3..093c65ddd0f585 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -82,13 +82,13 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
"Comparator has to be callable");
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
- __first,
- __last,
- __result_first,
- __result_last,
- static_cast<__comp_ref_type<_Compare> >(__comp),
- __identity(),
- __identity());
+ __first,
+ __last,
+ __result_first,
+ __result_last,
+ static_cast<__comp_ref_type<_Compare> >(__comp),
+ __identity(),
+ __identity());
return __result.second;
}
>From 9ae8d84b44742663a1da355d5eb53f6b831cfb43 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 14:59:21 -0500
Subject: [PATCH 25/31] clang-format
---
libcxx/include/__algorithm/partial_sort_copy.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 093c65ddd0f585..d86c93db913fa2 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -81,7 +81,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
"Comparator has to be callable");
- auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
+ auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
__first,
__last,
__result_first,
>From cbe637bb7f2ad3963616162fa1f3ee9479c85aee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 15:02:36 -0500
Subject: [PATCH 26/31] clang-format
---
.../include/__algorithm/partial_sort_copy.h | 101 +++++++-----------
1 file changed, 41 insertions(+), 60 deletions(-)
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index d86c93db913fa2..1d0f1db989f3fb 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -28,82 +28,63 @@
# pragma GCC system_header
#endif
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _AlgPolicy,
- class _Compare,
- class _InputIterator,
- class _Sentinel1,
- class _RandomAccessIterator,
- class _Sentinel2,
- class _Proj1,
- class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy(
- _InputIterator __first,
- _Sentinel1 __last,
- _RandomAccessIterator __result_first,
- _Sentinel2 __result_last,
- _Compare&& __comp,
- _Proj1&& __proj1,
- _Proj2&& __proj2) {
- _RandomAccessIterator __r = __result_first;
- auto&& __projected_comp = std::__make_projected(__comp, __proj2);
+template <class _AlgPolicy, class _Compare,
+ class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2,
+ class _Proj1, class _Proj2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator>
+__partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
+ _RandomAccessIterator __result_first, _Sentinel2 __result_last,
+ _Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2)
+{
+ _RandomAccessIterator __r = __result_first;
+ auto&& __projected_comp = std::__make_projected(__comp, __proj2);
- if (__r != __result_last) {
- for (; __first != __last && __r != __result_last; ++__first, (void)++__r)
- *__r = *__first;
- std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
- typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
- for (; __first != __last; ++__first)
- if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
- *__result_first = *__first;
- std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
- }
- std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
- }
+ if (__r != __result_last)
+ {
+ for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
+ *__r = *__first;
+ std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
+ for (; __first != __last; ++__first)
+ if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
+ *__result_first = *__first;
+ std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
+ }
+ std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
+ }
- return pair<_InputIterator, _RandomAccessIterator>(
- _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
+ return pair<_InputIterator, _RandomAccessIterator>(
+ _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
- _InputIterator __first,
- _InputIterator __last,
- _RandomAccessIterator __result_first,
- _RandomAccessIterator __result_last,
- _Compare __comp) {
- static_assert(
- __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
- static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
+_RandomAccessIterator
+partial_sort_copy(_InputIterator __first, _InputIterator __last,
+ _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
+{
+ static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
"Comparator has to be callable");
- auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
- __first,
- __last,
- __result_first,
- __result_last,
- static_cast<__comp_ref_type<_Compare> >(__comp),
- __identity(),
- __identity());
+ static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
+ "Comparator has to be callable");
+ auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
+ static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
return __result.second;
}
template <class _InputIterator, class _RandomAccessIterator>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
- _InputIterator __first,
- _InputIterator __last,
- _RandomAccessIterator __result_first,
- _RandomAccessIterator __result_last) {
- return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
+_RandomAccessIterator
+partial_sort_copy(_InputIterator __first, _InputIterator __last,
+ _RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
+{
+ return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
-_LIBCPP_POP_MACROS
-
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
>From d527109ac627746187aa16d213952d815311cfb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 15:11:21 -0500
Subject: [PATCH 27/31] clang-format
---
.../include/__algorithm/partial_sort_copy.h | 108 +++++++++++-------
1 file changed, 64 insertions(+), 44 deletions(-)
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 1d0f1db989f3fb..cbcc4da219ad68 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -28,63 +28,83 @@
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _AlgPolicy, class _Compare,
- class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2,
- class _Proj1, class _Proj2>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator>
-__partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
- _RandomAccessIterator __result_first, _Sentinel2 __result_last,
- _Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2)
-{
- _RandomAccessIterator __r = __result_first;
- auto&& __projected_comp = std::__make_projected(__comp, __proj2);
+template <class _AlgPolicy,
+ class _Compare,
+ class _InputIterator,
+ class _Sentinel1,
+ class _RandomAccessIterator,
+ class _Sentinel2,
+ class _Proj1,
+ class _Proj2>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy(
+ _InputIterator __first,
+ _Sentinel1 __last,
+ _RandomAccessIterator __result_first,
+ _Sentinel2 __result_last,
+ _Compare&& __comp,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
+ _RandomAccessIterator __r = __result_first;
+ auto&& __projected_comp = std::__make_projected(__comp, __proj2);
- if (__r != __result_last)
- {
- for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
- *__r = *__first;
- std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
- typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
- for (; __first != __last; ++__first)
- if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
- *__result_first = *__first;
- std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
- }
- std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
- }
+ if (__r != __result_last) {
+ for (; __first != __last && __r != __result_last; ++__first, (void)++__r)
+ *__r = *__first;
+ std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
+ typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
+ for (; __first != __last; ++__first)
+ if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
+ *__result_first = *__first;
+ std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
+ }
+ std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
+ }
- return pair<_InputIterator, _RandomAccessIterator>(
- _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
+ return pair<_InputIterator, _RandomAccessIterator>(
+ _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_RandomAccessIterator
-partial_sort_copy(_InputIterator __first, _InputIterator __last,
- _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
-{
- static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
- "Comparator has to be callable");
-
- static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
- "Comparator has to be callable");
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
+ _InputIterator __first,
+ _InputIterator __last,
+ _RandomAccessIterator __result_first,
+ _RandomAccessIterator __result_last,
+ _Compare __comp) {
+ static_assert(
+ __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
+ "Comparator has to be callable");
+ static_assert(
+ __is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
+ "Comparator has to be callable");
- auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
- static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
+ auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
+ __first,
+ __last,
+ __result_first,
+ __result_last,
+ static_cast<__comp_ref_type<_Compare> >(__comp),
+ __identity(),
+ __identity());
return __result.second;
}
template <class _InputIterator, class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
-_RandomAccessIterator
-partial_sort_copy(_InputIterator __first, _InputIterator __last,
- _RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
-{
- return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
+ _InputIterator __first,
+ _InputIterator __last,
+ _RandomAccessIterator __result_first,
+ _RandomAccessIterator __result_last) {
+ return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
}
_LIBCPP_END_NAMESPACE_STD
-#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
\ No newline at end of file
>From 70a5d77c0212c865b62cb8a54a6f9dfc08563162 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 15:17:30 -0500
Subject: [PATCH 28/31] clang-format
---
libcxx/include/__algorithm/partial_sort_copy.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index cbcc4da219ad68..4355ec2a4d5d82 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -77,11 +77,9 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
_RandomAccessIterator __result_last,
_Compare __comp) {
static_assert(
- __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
- "Comparator has to be callable");
- static_assert(
- __is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
- "Comparator has to be callable");
+ __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
+ static_assert(__is_callable<_Compare const&, decltype(*__first), decltype(*__result_first)>::value,
+ "Comparator has to be const-callable");
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
__first,
>From f2bb3e040ea0a104fd6edeffad407a356b949933 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nhat7203 at gmail.com>
Date: Sun, 18 Feb 2024 15:28:05 -0500
Subject: [PATCH 29/31] Update partial_sort_copy.h
---
libcxx/include/__algorithm/partial_sort_copy.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__algorithm/partial_sort_copy.h b/libcxx/include/__algorithm/partial_sort_copy.h
index 4355ec2a4d5d82..1bdc63265dce45 100644
--- a/libcxx/include/__algorithm/partial_sort_copy.h
+++ b/libcxx/include/__algorithm/partial_sort_copy.h
@@ -105,4 +105,4 @@ _LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
-#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
\ No newline at end of file
+#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
>From 4f8d4c9edd9406c7fdce815b6493a388c03f910d Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nhat at berkeley.edu>
Date: Mon, 19 Feb 2024 11:08:12 -0500
Subject: [PATCH 30/31] fix test
---
.../alg.nonmodifying/alg.search/search_pred.pass.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp
index f835d2f0945816..c86aeeaefef0f3 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_pred.pass.cpp
@@ -36,8 +36,11 @@ struct count_equal
{
static unsigned count;
template <class T>
- bool operator()(const T& x, const T& y)
- {++count; return x == y;}
+ bool operator()(const T& x, const T& y) &
+ {++count; return x == y;};
+ template<class T>
+ bool operator()(const T& x, const T& y) const&
+ {++count; return x == y;};
};
unsigned count_equal::count = 0;
>From 515d18a94a72e16f3c1f741f6a15c381ca6f3bf5 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nhat at berkeley.edu>
Date: Mon, 19 Feb 2024 15:31:20 -0500
Subject: [PATCH 31/31] fix test
---
.../algorithms/const_callable.verify.cpp | 18 +++++++++++++-----
.../is_permutation_pred.pass.cpp | 3 ++-
.../alg.search/search_n_pred.pass.cpp | 11 +++++++++--
.../alg.merge/inplace_merge_comp.pass.cpp | 11 ++++++++---
.../stable.sort/stable_sort_comp.pass.cpp | 6 ++----
5 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/libcxx/test/libcxx/algorithms/const_callable.verify.cpp b/libcxx/test/libcxx/algorithms/const_callable.verify.cpp
index 5085bd1eef135e..d6f27f48ab8d27 100644
--- a/libcxx/test/libcxx/algorithms/const_callable.verify.cpp
+++ b/libcxx/test/libcxx/algorithms/const_callable.verify.cpp
@@ -9,16 +9,24 @@
#include <algorithm>
struct ConstUncallable {
- void operator()(int, int) const& = delete;
- void operator()(int, int) & { return; }
+ template <class T>
+ bool operator()(T, T) const& = delete;
+ template <class T>
+ bool operator()(T, T) & {
+ return true;
+ }
};
struct NonConstUncallable {
- void operator()(int, int) const& { return; }
- void operator()(int, int) & = delete;
+ template <class T>
+ bool operator()(T, T) const& {
+ return true;
+ }
+ template <class T>
+ bool operator()(T, T) & = delete;
};
void test() {
- std::minmax({42, 0, -42}, ConstUncallable{});
+ std::minmax({42, 0, -42}, ConstUncallable());
//expected-error-re@*:* {{static_assert(__is_callable<_Compare const&, decltype(*__first), const _Tp&>::value, "The comparator has to be const-callable")}}
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
index ea4270ec4095bb..08176071ea1202 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
@@ -51,7 +51,8 @@ struct S {
};
struct eq {
- bool operator()(const S& a, const S&b) { return a.i_ == b.i_; }
+ bool operator()(const S& a, const S& b) & { return a.i_ == b.i_; }
+ bool operator()(const S& a, const S& b) const& { return a.i_ == b.i_; }
};
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
index 3bf72e3fbf57ba..570c3874a311ec 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
@@ -36,8 +36,15 @@ struct count_equal
{
static unsigned count;
template <class T>
- bool operator()(const T& x, const T& y)
- {++count; return x == y;}
+ bool operator()(const T& x, const T& y) & {
+ ++count;
+ return x == y;
+ }
+ template <class T>
+ bool operator()(const T& x, const T& y) const& {
+ ++count;
+ return x == y;
+ }
};
unsigned count_equal::count = 0;
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
index 0a35fad40e89a5..ec7fb82fbcb9bf 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
@@ -26,9 +26,14 @@
struct indirect_less
{
- template <class P>
- bool operator()(const P& x, const P& y)
- {return *x < *y;}
+ template <class P>
+ bool operator()(const P& x, const P& y) & {
+ return *x < *y;
+ }
+ template <class P>
+ bool operator()(const P& x, const P& y) const& {
+ return *x < *y;
+ }
};
struct S {
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp
index 46c2a42349df7d..bf00fd7baaca8a 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort_comp.pass.cpp
@@ -36,10 +36,8 @@ std::mt19937 randomness;
struct first_only
{
- bool operator()(const std::pair<int, int>& x, const std::pair<int, int>& y)
- {
- return x.first < y.first;
- }
+ bool operator()(const std::pair<int, int>& x, const std::pair<int, int>& y) & { return x.first < y.first; }
+ bool operator()(const std::pair<int, int>& x, const std::pair<int, int>& y) const& { return x.first < y.first; }
};
void test()
More information about the libcxx-commits
mailing list