| 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 <cassert> |
| 24 | #include <vector> |
| 25 | |
| 26 | #include "test_macros.h" |
| 27 | #include "test_execution_policies.h" |
| 28 | #include "test_iterators.h" |
| 29 | |
| 30 | // We can't test the constraint on the execution policy, because that would conflict with the binary |
| 31 | // transform algorithm that doesn't take an execution policy, which is not constrained at all. |
| 32 | |
| 33 | template <class Iter1, class Iter2> |
| 34 | struct Test { |
| 35 | template <class Policy> |
| 36 | void operator()(Policy&& policy) { |
| 37 | // simple test |
| 38 | for (const int size : {0, 1, 2, 100, 350}) { |
| 39 | std::vector<int> a(size); |
| 40 | for (int i = 0; i != size; ++i) |
| 41 | a[i] = i + 1; |
| 42 | |
| 43 | std::vector<int> out(std::size(cont: a)); |
| 44 | decltype(auto) ret = std::transform( |
| 45 | policy, Iter1(std::data(cont&: a)), Iter1(std::data(cont&: a) + std::size(cont: a)), Iter2(std::data(cont&: out)), [](int i) { |
| 46 | return i + 3; |
| 47 | }); |
| 48 | static_assert(std::is_same_v<decltype(ret), Iter2>); |
| 49 | assert(base(ret) == std::data(out) + std::size(out)); |
| 50 | for (int i = 0; i != size; ++i) |
| 51 | assert(out[i] == i + 4); |
| 52 | } |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | int main(int, char**) { |
| 57 | types::for_each(types::forward_iterator_list<int*>{}, types::apply_type_identity{[](auto v) { |
| 58 | using Iter = typename decltype(v)::type; |
| 59 | types::for_each( |
| 60 | types::forward_iterator_list<int*>{}, |
| 61 | TestIteratorWithPolicies<types::partial_instantiation<Test, Iter>::template apply>{}); |
| 62 | }}); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |