[libcxx-commits] [libcxx] [libc++] Forward std::is_sorted_until to std::adjacent_find (PR #168687)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 19 01:55:50 PST 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/168687

None

>From a724128b40828c0be4dab1ae322d518c2cfee227 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 19 Nov 2025 10:55:19 +0100
Subject: [PATCH] [libc++] Forward std::is_sorted_until to std::adjacent_find

---
 libcxx/include/__algorithm/is_sorted_until.h | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/libcxx/include/__algorithm/is_sorted_until.h b/libcxx/include/__algorithm/is_sorted_until.h
index 606641949db98..bf2db80bd9036 100644
--- a/libcxx/include/__algorithm/is_sorted_until.h
+++ b/libcxx/include/__algorithm/is_sorted_until.h
@@ -9,6 +9,7 @@
 #ifndef _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
 #define _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
 
+#include <__algorithm/adjacent_find.h>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__config>
@@ -22,15 +23,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template <class _Compare, class _ForwardIterator>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
 __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
-  if (__first != __last) {
-    _ForwardIterator __i = __first;
-    while (++__i != __last) {
-      if (__comp(*__i, *__first))
-        return __i;
-      __first = __i;
-    }
-  }
-  return __last;
+  return std::adjacent_find(__first, __last, [&](decltype(*__first) __lhs, decltype(*__first) __rhs) {
+    return __comp(__rhs, __lhs);
+  });
 }
 
 template <class _ForwardIterator, class _Compare>



More information about the libcxx-commits mailing list