[libcxx-commits] [libcxx] [libc++][pstl] Default implementation of parallel std::find_first_of (PR #206328)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 2 13:09:14 PDT 2026


================
@@ -181,6 +183,25 @@ struct __is_partitioned<__default_backend_tag, _ExecutionPolicy> {
   }
 };
 
+template <class _ExecutionPolicy>
+struct __find_first_of<__default_backend_tag, _ExecutionPolicy> {
+  template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator1>
+  operator()(_Policy&& __policy,
+             _ForwardIterator1 __first1,
+             _ForwardIterator1 __last1,
+             _ForwardIterator2 __first2,
+             _ForwardIterator2 __last2,
+             _Predicate&& __pred) const noexcept {
+    using _FindIf = __dispatch<__find_if, __current_configuration, _ExecutionPolicy>;
+    using _Ref1   = __iterator_reference<_ForwardIterator1>;
+    using _Ref2   = __iterator_reference<_ForwardIterator2>;
+    return _FindIf()(__policy, std::move(__first1), std::move(__last1), [&](_Ref1 __element) {
+      return std::any_of(__first2, __last2, [&](_Ref2 __value) { return __pred(__element, __value); });
+    });
----------------
ldionne wrote:

Yeah, I think that's the best approach for now.

For some reason I thought `any_of` was built on top of `find_if`, that's why I've been talking about these vectorization opportunities in the first place. Oh well, we should implement `any_of` as `find_if` anyway.

https://github.com/llvm/llvm-project/pull/206328


More information about the libcxx-commits mailing list