[libcxx-commits] [libcxx] [libc++][pstl] Generic implementation of parallel std::is_sorted_until (PR #178756)
Michael G. Kazakov via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 16 10:25:18 PST 2026
mikekazakov wrote:
Yes, absolutely, `is_sorted_until` can be trivially implemented as a call to `adjacent_find`.
I have its implementation and the code is almost identical to `is_sorted_until` in this PR.
I can add `adjacent_find` to this PR as well and rebase both `is_sorted` and `is_sorted_until` on top of that.
Not sure about making `adjacent_find` a fundamental operation though - it's trivially implementable on top of `find_if`, e.g.:
```c++
using _DifferenceType = typename std::iterator_traits<_ForwardIterator>::difference_type;
using _IndexIteratorType = __index_iterator<_DifferenceType>;
_DifferenceType __n = __last - __first;
if (__n <= 1)
return __last; // Cannot be found by definition
_IndexIteratorType __index_first{_DifferenceType{}};
_IndexIteratorType __index_last{__n - 1};
using _FindIf = __dispatch<__find_if, __current_configuration, _ExecutionPolicy>;
auto __res = _FindIf()(__policy, __index_first, __index_last, [&](_DifferenceType __index) -> bool {
return __pred(*(__first + __index), *(__first + __index + 1));
});
if (!__res)
return nullopt;
if( *__res == __index_last )
return __last; // Not found
return __first + *(*__res);
```
https://github.com/llvm/llvm-project/pull/178756
More information about the libcxx-commits
mailing list