1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
15 // template<class ExecutionPolicy, class ForwardIterator, class Function>
16 // void for_each(ExecutionPolicy&& exec,
17 // ForwardIterator first, ForwardIterator last,
25 #include "test_macros.h"
26 #include "test_execution_policies.h"
27 #include "test_iterators.h"
29 EXECUTION_POLICY_SFINAE_TEST(for_each
);
31 static_assert(sfinae_test_for_each
<int, int*, int*, bool (*)(int)>);
32 static_assert(!sfinae_test_for_each
<std::execution::parallel_policy
, int*, int*, bool (*)(int)>);
36 template <class Policy
>
37 void operator()(Policy
&& policy
) {
38 int sizes
[] = {0, 1, 2, 100};
39 for (auto size
: sizes
) {
40 std::vector
<int> a(size
);
41 std::vector
<Bool
> called(size
);
42 std::for_each(policy
, Iter(std::data(a
)), Iter(std::data(a
) + std::size(a
)), [&](int& v
) {
43 assert(!called
[&v
- a
.data()]);
44 called
[&v
- a
.data()] = true;
46 assert(std::all_of(std::begin(called
), std::end(called
), [](bool b
) { return b
; }));
51 int main(int, char**) {
52 types::for_each(types::forward_iterator_list
<int*>{}, TestIteratorWithPolicies
<Test
>{});