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,
16 // class ForwardIterator, class T,
17 // class BinaryOperation, class UnaryOperation>
18 // T transform_reduce(ExecutionPolicy&& exec,
19 // ForwardIterator first, ForwardIterator last,
20 // T init, BinaryOperation binary_op, UnaryOperation unary_op);
27 #include "test_execution_policies.h"
28 #include "test_iterators.h"
29 #include "test_macros.h"
31 template <class Iter1
, class ValueT
>
33 template <class Policy
>
34 void operator()(Policy
&& policy
) {
35 for (const auto& pair
: {std::pair
{0, 34}, {1, 35}, {2, 37}, {100, 5084}, {350, 61459}}) {
36 auto [size
, expected
] = pair
;
37 std::vector
<int> a(size
);
38 for (int i
= 0; i
!= size
; ++i
)
41 decltype(auto) ret
= std::transform_reduce(
44 Iter1(std::data(a
) + std::size(a
)),
46 [check
= std::string("Banane")](ValueT i
, ValueT j
) {
47 assert(check
== "Banane"); // ensure that no double-moves happen
50 [check
= std::string("Banane")](ValueT i
) {
51 assert(check
== "Banane"); // ensure that no double-moves happen
54 static_assert(std::is_same_v
<decltype(ret
), ValueT
>);
55 assert(ret
== expected
);
60 int main(int, char**) {
61 types::for_each(types::forward_iterator_list
<int*>{}, types::apply_type_identity
{[](auto v
) {
62 using Iter2
= typename
decltype(v
)::type
;
64 types::type_list
<int, MoveOnly
>{},
65 TestIteratorWithPolicies
<types::partial_instantiation
<Test
, Iter2
>::template apply
>{});