| 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 ForwardIterator, class BinaryOperation> |
| 17 |
// ForwardIterator |
| 18 |
// transform(ExecutionPolicy&& exec, |
| 19 |
// ForwardIterator1 first1, ForwardIterator1 last1, |
| 20 |
// ForwardIterator2 first2, ForwardIterator result, |
| 21 |
// BinaryOperation binary_op); |
| 22 |
|
| 23 |
#include <algorithm> |
| 24 |
#include <vector> |
| 25 |
|
| 26 |
#include "test_macros.h" |
| 27 |
#include "test_execution_policies.h" |
| 28 |
#include "test_iterators.h" |
| 29 |
|
| 30 |
EXECUTION_POLICY_SFINAE_TEST(transform); |
| 31 |
|
| 32 |
static_assert(sfinae_test_transform<int, int*, int*, int*, int*, bool (*)(int)>); |
| 33 |
static_assert(!sfinae_test_transform<std::execution::parallel_policy, int*, int*, int*, int*, int (*)(int, int)>); |
| 34 |
|
| 35 |
template <class Iter1, class Iter2, class Iter3> |
| 36 |
struct Test { |
| 37 |
template <class Policy> |
| 38 |
void operator()(Policy&& policy) { |
| 39 |
// simple test |
| 40 |
for (const int size : {0, 1, 2, 100, 350}) { |
| 41 |
std::vector<int> a(size); |
| 42 |
std::vector<int> b(size); |
| 43 |
for (int i = 0; i != size; ++i) { |
| 44 |
a[i] = i + 1; |
| 45 |
b[i] = i - 3; |
| 46 |
} |
| 47 |
|
| 48 |
std::vector<int> out(std::size(a)); |
| 49 |
decltype(auto) ret = std::transform( |
| 50 |
policy, |
| 51 |
Iter1(std::data(a)), |
| 52 |
Iter1(std::data(a) + std::size(a)), |
| 53 |
Iter2(std::data(b)), |
| 54 |
Iter3(std::data(out)), |
| 55 |
[](int i, int j) { return i + j + 3; }); |
| 56 |
static_assert(std::is_same_v<decltype(ret), Iter3>); |
| 57 |
assert(base(ret) == std::data(out) + std::size(out)); |
| 58 |
for (int i = 0; i != size; ++i) { |
| 59 |
assert(out[i] == i * 2 + 1); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
int main(int, char**) { |
| 66 |
types::for_each( |
| 67 |
types::forward_iterator_list<int*>{}, types::apply_type_identity{[](auto v) { |
| 68 |
using Iter3 = typename decltype(v)::type; |
| 69 |
types::for_each( |
| 70 |
types::forward_iterator_list<int*>{}, types::apply_type_identity{[](auto v2) { |
| 71 |
using Iter2 = typename decltype(v2)::type; |
| 72 |
types::for_each( |
| 73 |
types::forward_iterator_list<int*>{}, |
| 74 |
TestIteratorWithPolicies<types::partial_instantiation<Test, Iter2, Iter3>::template apply>{}); |
| 75 |
}}); |
| 76 |
}}); |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |