1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 
11 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
12 
13 // <algorithm>
14 
15 // template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
16 //          class UnaryOperation>
17 //   ForwardIterator2
18 //     transform(ExecutionPolicy&& exec,
19 //               ForwardIterator1 first1, ForwardIterator1 last1,
20 //               ForwardIterator2 result, UnaryOperation op);
21 
22 #include <algorithm>
23 #include <vector>
24 
25 #include "test_macros.h"
26 #include "test_execution_policies.h"
27 #include "test_iterators.h"
28 
29 // We can't test the constraint on the execution policy, because that would conflict with the binary
30 // transform algorithm that doesn't take an execution policy, which is not constrained at all.
31 
32 template <class Iter1, class Iter2>
33 struct Test {
34   template <class Policy>
35   void operator()(Policy&& policy) {
36     // simple test
37     for (const int size : {0, 1, 2, 100, 350}) {
38       std::vector<int> a(size);
39       for (int i = 0; i != size; ++i)
40         a[i] = i + 1;
41 
42       std::vector<int> out(std::size(a));
43       decltype(auto) ret = std::transform(
44           policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::data(out)), [](int i) {
45             return i + 3;
46           });
47       static_assert(std::is_same_v<decltype(ret), Iter2>);
48       assert(base(ret) == std::data(out) + std::size(out));
49       for (int i = 0; i != size; ++i)
50         assert(out[i] == i + 4);
51     }
52   }
53 };
54 
55 struct TestIterators {
56   template <class Iter2>
57   void operator()() {
58     types::for_each(types::forward_iterator_list<int*>{},
59                     TestIteratorWithPolicies<types::partial_instantiation<Test, Iter2>::template apply>{});
60   }
61 };
62 
63 int main(int, char**) {
64   types::for_each(types::forward_iterator_list<int*>{}, TestIterators{});
65 
66   return 0;
67 }
68