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 ForwardIterator1, class ForwardIterator2,
16 // class UnaryOperation>
18 // transform(ExecutionPolicy&& exec,
19 // ForwardIterator1 first1, ForwardIterator1 last1,
20 // ForwardIterator2 result, UnaryOperation op);
26 #include "test_macros.h"
27 #include "test_execution_policies.h"
28 #include "test_iterators.h"
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.
33 template <class Iter1
, class Iter2
>
35 template <class Policy
>
36 void operator()(Policy
&& policy
) {
38 for (const int size
: {0, 1, 2, 100, 350}) {
39 std::vector
<int> a(size
);
40 for (int i
= 0; i
!= size
; ++i
)
43 std::vector
<int> out(std::size(a
));
44 decltype(auto) ret
= std::transform(
45 policy
, Iter1(std::data(a
)), Iter1(std::data(a
) + std::size(a
)), Iter2(std::data(out
)), [](int i
) {
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);
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
;
60 types::forward_iterator_list
<int*>{},
61 TestIteratorWithPolicies
<types::partial_instantiation
<Test
, Iter
>::template apply
>{});