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 ForwardIterator, class BinaryOperation>
18 // transform(ExecutionPolicy&& exec,
19 // ForwardIterator1 first1, ForwardIterator1 last1,
20 // ForwardIterator2 first2, ForwardIterator result,
21 // BinaryOperation binary_op);
26 #include "test_macros.h"
27 #include "test_execution_policies.h"
28 #include "test_iterators.h"
30 EXECUTION_POLICY_SFINAE_TEST(transform
);
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)>);
35 template <class Iter1
, class Iter2
, class Iter3
>
37 template <class Policy
>
38 void operator()(Policy
&& policy
) {
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
) {
48 std::vector
<int> out(std::size(a
));
49 decltype(auto) ret
= std::transform(
52 Iter1(std::data(a
) + std::size(a
)),
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);
65 int main(int, char**) {
67 types::forward_iterator_list
<int*>{}, types::apply_type_identity
{[](auto v
) {
68 using Iter3
= typename
decltype(v
)::type
;
70 types::forward_iterator_list
<int*>{}, types::apply_type_identity
{[](auto v2
) {
71 using Iter2
= typename
decltype(v2
)::type
;
73 types::forward_iterator_list
<int*>{},
74 TestIteratorWithPolicies
<types::partial_instantiation
<Test
, Iter2
, Iter3
>::template apply
>{});