[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
Sun Feb 18 11:48:17 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>
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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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,



More information about the libcxx-commits mailing list