• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <numeric>
11 
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_iterators.h"
24 
25 template <class InIter, class OutIter>
26 void
test()27 test()
28 {
29     int ia[] = {1, 2, 3, 4, 5};
30     int ir[] = {1, 3, 6, 10, 15};
31     const unsigned s = sizeof(ia) / sizeof(ia[0]);
32     int ib[s] = {0};
33     OutIter r = std::partial_sum(InIter(ia), InIter(ia+s), OutIter(ib));
34     assert(base(r) == ib + s);
35     for (unsigned i = 0; i < s; ++i)
36         assert(ib[i] == ir[i]);
37 }
38 
main()39 int main()
40 {
41     test<input_iterator<const int*>, output_iterator<int*> >();
42     test<input_iterator<const int*>, forward_iterator<int*> >();
43     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
44     test<input_iterator<const int*>, random_access_iterator<int*> >();
45     test<input_iterator<const int*>, int*>();
46 
47     test<forward_iterator<const int*>, output_iterator<int*> >();
48     test<forward_iterator<const int*>, forward_iterator<int*> >();
49     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
50     test<forward_iterator<const int*>, random_access_iterator<int*> >();
51     test<forward_iterator<const int*>, int*>();
52 
53     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
54     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
55     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
56     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
57     test<bidirectional_iterator<const int*>, int*>();
58 
59     test<random_access_iterator<const int*>, output_iterator<int*> >();
60     test<random_access_iterator<const int*>, forward_iterator<int*> >();
61     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
62     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
63     test<random_access_iterator<const int*>, int*>();
64 
65     test<const int*, output_iterator<int*> >();
66     test<const int*, forward_iterator<int*> >();
67     test<const int*, bidirectional_iterator<int*> >();
68     test<const int*, random_access_iterator<int*> >();
69     test<const int*, int*>();
70 }
71