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 ForwardIterator>
16 // typename iterator_traits<ForwardIterator>::value_type
17 // reduce(ExecutionPolicy&& exec,
18 // ForwardIterator first, ForwardIterator last);
19 // template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
20 // T reduce(ExecutionPolicy&& exec,
21 // ForwardIterator first, ForwardIterator last, T init,
22 // BinaryOperation binary_op);
28 #include "test_execution_policies.h"
29 #include "test_iterators.h"
30 #include "test_macros.h"
32 template <class Iter
, class ValueT
>
34 template <class Policy
>
35 void operator()(Policy
&& policy
) {
36 for (const auto& pair
: {std::pair
{0, 34}, {1, 36}, {2, 39}, {100, 5184}, {350, 61809}}) {
37 auto [size
, expected
] = pair
;
38 std::vector
<int> a(size
);
39 for (int i
= 0; i
!= size
; ++i
)
43 decltype(auto) ret
= std::reduce(
44 policy
, Iter(std::data(a
)), Iter(std::data(a
) + std::size(a
)), ValueT(34), [](ValueT i
, ValueT j
) {
47 static_assert(std::is_same_v
<decltype(ret
), ValueT
>);
48 assert(ret
== ValueT(expected
));
51 decltype(auto) ret
= std::reduce(policy
, Iter(std::data(a
)), Iter(std::data(a
) + std::size(a
)), ValueT(34));
52 static_assert(std::is_same_v
<decltype(ret
), ValueT
>);
53 assert(ret
== expected
- 2 * size
);
56 decltype(auto) ret
= std::reduce(policy
, Iter(std::data(a
)), Iter(std::data(a
) + std::size(a
)));
57 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::value_type
>);
58 assert(ret
== expected
- 2 * size
- 34);
64 int main(int, char**) {
65 types::for_each(types::forward_iterator_list
<int*>{}, types::apply_type_identity
{[](auto v
) {
66 using Iter
= typename
decltype(v
)::type
;
68 types::type_list
<int, MoveOnly
>{},
69 TestIteratorWithPolicies
<types::partial_instantiation
<Test
, Iter
>::template apply
>{});