• 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,
13 //          OutputIterator<auto, const InIter::value_type&> OutIter,
14 //          Callable<auto, const InIter::value_type&, InIter::reference> BinaryOperation>
15 //   requires HasAssign<InIter::value_type, BinaryOperation::result_type>
16 //         && Constructible<InIter::value_type, InIter::reference>
17 //         && CopyConstructible<BinaryOperation>
18 //   OutIter
19 //   partial_sum(InIter first, InIter last, OutIter result, BinaryOperation binary_op);
20 
21 #include <numeric>
22 #include <functional>
23 #include <cassert>
24 
25 #include "test_iterators.h"
26 
27 template <class InIter, class OutIter>
28 void
test()29 test()
30 {
31     int ia[] = {1, 2, 3, 4, 5};
32     int ir[] = {1, -1, -4, -8, -13};
33     const unsigned s = sizeof(ia) / sizeof(ia[0]);
34     int ib[s] = {0};
35     OutIter r = std::partial_sum(InIter(ia), InIter(ia+s), OutIter(ib), std::minus<int>());
36     assert(base(r) == ib + s);
37     for (unsigned i = 0; i < s; ++i)
38         assert(ib[i] == ir[i]);
39 }
40 
main()41 int main()
42 {
43     test<input_iterator<const int*>, output_iterator<int*> >();
44     test<input_iterator<const int*>, forward_iterator<int*> >();
45     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
46     test<input_iterator<const int*>, random_access_iterator<int*> >();
47     test<input_iterator<const int*>, int*>();
48 
49     test<forward_iterator<const int*>, 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*>, 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*>, 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*, 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