[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
Wed Jul 1 09:47:56 PDT 2026
================
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++17
+
+// UNSUPPORTED: libcpp-has-no-incomplete-pstl
+
+// template <class ExecutionPolicy,
+// class ForwardIterator1,
+// class ForwardIterator2>
+// ForwardIterator1 find_first_of(ExecutionPolicy&& exec,
+// ForwardIterator1 first1,
+// ForwardIterator1 last1,
+// ForwardIterator2 first2,
+// ForwardIterator2 last2);
+
+#include <algorithm>
+#include <cassert>
+#include <functional>
+#include <limits>
+#include <numeric>
+
+#include "test_execution_policies.h"
+#include "test_iterators.h"
+#include "test_macros.h"
+#include "type_algorithms.h"
+
+template <class Iter>
+struct Test {
+ template <class ExecutionPolicy>
+ void operator()(ExecutionPolicy&& policy) {
+ {
+ int a[] = {0};
+ unsigned sa = sizeof(a) / sizeof(a[0]);
+ assert(std::find_first_of(policy, Iter(a), Iter(a), Iter(a), Iter(a)) == Iter(a));
+ assert(std::find_first_of(policy, Iter(a), Iter(a + sa), Iter(a), Iter(a)) == Iter(a + sa));
+ }
+ {
+ int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
+ unsigned sa = sizeof(ia) / sizeof(ia[0]);
+ int ib[] = {1, 3, 5, 7};
+ unsigned sb = sizeof(ib) / sizeof(ib[0]);
+ assert(std::find_first_of(policy, Iter(ia), Iter(ia + sa), Iter(ib), Iter(ib + sb)) == Iter(ia + 1));
+ int ic[] = {7};
+ assert(std::find_first_of(policy, Iter(ia), Iter(ia + sa), Iter(ic), Iter(ic + 1)) == Iter(ia + sa));
+ assert(std::find_first_of(policy, Iter(ia), Iter(ia + sa), Iter(ic), Iter(ic)) == Iter(ia + sa));
+ assert(std::find_first_of(policy, Iter(ia), Iter(ia), Iter(ic), Iter(ic + 1)) == Iter(ia));
+ }
+ {
+ int a[8192];
----------------
ldionne wrote:
Yeah, I looked at the existing tests for `find_first_of` and they're not great, really. Adding just this should be possible without messing with C++03 though?
```c++
// in main()
{
using Iter = forward_iterator<const int*>;
int a[8192];
std::iota(begin(a), end(a), 1);
a[1023] = -1;
a[2048] = -1;
a[3071] = -1;
int b[] = {-1, 999999};
assert(std::find_first_of(policy, Iter(begin(a)), Iter(end(a)), Iter(begin(b)), Iter(end(b))) ==
Iter(begin(a) + 1023));
}
```
That's not addressing the whole gap in coverage, but it captures the added "runtime" coverage here and makes it likely that we'd pick this up when refactoring that test. WDYT?
https://github.com/llvm/llvm-project/pull/206328
More information about the libcxx-commits
mailing list