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 //===----------------------------------------------------------------------===//
11 // Became constexpr in C++20
12 // template <InputIterator InIter, OutputIterator<auto, const InIter::value_type&> OutIter>
13 // requires HasPlus<InIter::value_type, InIter::reference>
14 // && HasAssign<InIter::value_type,
15 // HasPlus<InIter::value_type, InIter::reference>::result_type>
16 // && Constructible<InIter::value_type, InIter::reference>
18 // partial_sum(InIter first, InIter last, OutIter result);
23 #include "test_macros.h"
24 #include "test_iterators.h"
26 template <class InIter
, class OutIter
>
27 TEST_CONSTEXPR_CXX20
void
30 int ia
[] = {1, 2, 3, 4, 5};
31 int ir
[] = {1, 3, 6, 10, 15};
32 const unsigned s
= sizeof(ia
) / sizeof(ia
[0]);
34 OutIter r
= std::partial_sum(InIter(ia
), InIter(ia
+s
), OutIter(ib
));
35 assert(base(r
) == ib
+ s
);
36 for (unsigned i
= 0; i
< s
; ++i
)
37 assert(ib
[i
] == ir
[i
]);
40 TEST_CONSTEXPR_CXX20
bool
43 test
<cpp17_input_iterator
<const int*>, cpp17_output_iterator
<int*> >();
44 test
<cpp17_input_iterator
<const int*>, forward_iterator
<int*> >();
45 test
<cpp17_input_iterator
<const int*>, bidirectional_iterator
<int*> >();
46 test
<cpp17_input_iterator
<const int*>, random_access_iterator
<int*> >();
47 test
<cpp17_input_iterator
<const int*>, int*>();
49 test
<forward_iterator
<const int*>, cpp17_output_iterator
<int*> >();
50 test
<forward_iterator
<const int*>, forward_iterator
<int*> >();
51 test
<forward_iterator
<const int*>, bidirectional_iterator
<int*> >();
52 test
<forward_iterator
<const int*>, random_access_iterator
<int*> >();
53 test
<forward_iterator
<const int*>, int*>();
55 test
<bidirectional_iterator
<const int*>, cpp17_output_iterator
<int*> >();
56 test
<bidirectional_iterator
<const int*>, forward_iterator
<int*> >();
57 test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >();
58 test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >();
59 test
<bidirectional_iterator
<const int*>, int*>();
61 test
<random_access_iterator
<const int*>, cpp17_output_iterator
<int*> >();
62 test
<random_access_iterator
<const int*>, forward_iterator
<int*> >();
63 test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >();
64 test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >();
65 test
<random_access_iterator
<const int*>, int*>();
67 test
<const int*, cpp17_output_iterator
<int*> >();
68 test
<const int*, forward_iterator
<int*> >();
69 test
<const int*, bidirectional_iterator
<int*> >();
70 test
<const int*, random_access_iterator
<int*> >();
71 test
<const int*, int*>();
80 static_assert(test());