Skip to content

Commit a724128

Browse files
committed
[libc++] Forward std::is_sorted_until to std::adjacent_find
1 parent 577b519 commit a724128

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

libcxx/include/__algorithm/is_sorted_until.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
1010
#define _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
1111

12+
#include <__algorithm/adjacent_find.h>
1213
#include <__algorithm/comp.h>
1314
#include <__algorithm/comp_ref_type.h>
1415
#include <__config>
@@ -22,15 +23,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2223
template <class _Compare, class _ForwardIterator>
2324
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
2425
__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
25-
if (__first != __last) {
26-
_ForwardIterator __i = __first;
27-
while (++__i != __last) {
28-
if (__comp(*__i, *__first))
29-
return __i;
30-
__first = __i;
31-
}
32-
}
33-
return __last;
26+
return std::adjacent_find(__first, __last, [&](decltype(*__first) __lhs, decltype(*__first) __rhs) {
27+
return __comp(__rhs, __lhs);
28+
});
3429
}
3530

3631
template <class _ForwardIterator, class _Compare>

0 commit comments

Comments
 (0)