| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <numeric> |
| 10 |
|
| 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> |
| 17 |
// OutIter |
| 18 |
// partial_sum(InIter first, InIter last, OutIter result); |
| 19 |
|
| 20 |
#include <numeric> |
| 21 |
#include <cassert> |
| 22 |
|
| 23 |
#include "test_macros.h" |
| 24 |
#include "test_iterators.h" |
| 25 |
|
| 26 |
template <class InIter, class OutIter> |
| 27 |
TEST_CONSTEXPR_CXX20 void |
| 28 |
test() |
| 29 |
{ |
| 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]); |
| 33 |
int ib[s] = {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]); |
| 38 |
} |
| 39 |
|
| 40 |
TEST_CONSTEXPR_CXX20 bool |
| 41 |
test() |
| 42 |
{ |
| 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*>(); |
| 48 |
|
| 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*>(); |
| 54 |
|
| 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*>(); |
| 60 |
|
| 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*>(); |
| 66 |
|
| 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*>(); |
| 72 |
|
| 73 |
return true; |
| 74 |
} |
| 75 |
|
| 76 |
int main(int, char**) |
| 77 |
{ |
| 78 |
test(); |
| 79 |
#if TEST_STD_VER > 17 |
| 80 |
static_assert(test()); |
| 81 |
#endif |
| 82 |
return 0; |
| 83 |
} |