[libcxx-commits] [libcxx] [libc++][pstl] Implementation of parallel std::lexicographical_compare() based on std::mismatch() (PR #212366)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 29 08:57:00 PDT 2026
================
@@ -221,6 +222,33 @@ struct __find_first_of<__default_backend_tag, _ExecutionPolicy> {
// mismatch family
//////////////////////////////////////////////////////////////
+template <class _ExecutionPolicy>
+struct __lexicographical_compare<__default_backend_tag, _ExecutionPolicy> {
+ template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Comp>
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
+ operator()(_Policy&& __policy,
+ _ForwardIterator1 __first1,
+ _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2,
+ _Comp __comp) const noexcept {
+ using _Mismatch = __dispatch<__mismatch, __current_configuration, _ExecutionPolicy>;
+ using _Ref1 = __iterator_reference<_ForwardIterator1>;
+ using _Ref2 = __iterator_reference<_ForwardIterator2>;
+ // find the first pair of elements that are not equal, or the end of one or both of the ranges
+ auto __res = _Mismatch()(__policy, __first1, __last1, __first2, __last2, [&](_Ref1 __lhs, _Ref2 __rhs) {
+ return !__comp(__lhs, __rhs) && !__comp(__rhs, __lhs); // derive equality from the less-than predicate
----------------
ldionne wrote:
Per https://eel.is/c++draft/alg.sorting#general-3, `comp` is a strict weak order, so there's no question whether this is valid: it definitely is.
https://github.com/llvm/llvm-project/pull/212366
More information about the libcxx-commits
mailing list