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 Iter, MoveConstructible T,
13//           Callable<auto, const T&, Iter::reference> BinaryOperation>
14//   requires HasAssign<T, BinaryOperation::result_type>
15//         && CopyConstructible<BinaryOperation>
16//   T
17//   accumulate(Iter first, Iter last, T init, BinaryOperation binary_op);
18
19#include <numeric>
20#include <functional>
21#include <cassert>
22
23#include "test_iterators.h"
24
25template <class Iter, class T>
26void
27test(Iter first, Iter last, T init, T x)
28{
29    assert(std::accumulate(first, last, init, std::multiplies<T>()) == x);
30}
31
32template <class Iter>
33void
34test()
35{
36    int ia[] = {1, 2, 3, 4, 5, 6};
37    unsigned sa = sizeof(ia) / sizeof(ia[0]);
38    test(Iter(ia), Iter(ia), 1, 1);
39    test(Iter(ia), Iter(ia), 10, 10);
40    test(Iter(ia), Iter(ia+1), 1, 1);
41    test(Iter(ia), Iter(ia+1), 10, 10);
42    test(Iter(ia), Iter(ia+2), 1, 2);
43    test(Iter(ia), Iter(ia+2), 10, 20);
44    test(Iter(ia), Iter(ia+sa), 1, 720);
45    test(Iter(ia), Iter(ia+sa), 10, 7200);
46}
47
48int main()
49{
50    test<input_iterator<const int*> >();
51    test<forward_iterator<const int*> >();
52    test<bidirectional_iterator<const int*> >();
53    test<random_access_iterator<const int*> >();
54    test<const int*>();
55}
56