Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <numeric> |
| 11 | |
Howard Hinnant | a0eaf60 | 2010-08-22 00:42:21 +0000 | [diff] [blame] | 12 | // template <InputIterator Iter, MoveConstructible T> |
| 13 | // requires HasPlus<T, Iter::reference> |
| 14 | // && HasAssign<T, HasPlus<T, Iter::reference>::result_type> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | // T |
| 16 | // accumulate(Iter first, Iter last, T init); |
| 17 | |
| 18 | #include <numeric> |
| 19 | #include <cassert> |
| 20 | |
Marshall Clow | 3222708 | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 21 | #include "test_iterators.h" |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
| 23 | template <class Iter, class T> |
| 24 | void |
| 25 | test(Iter first, Iter last, T init, T x) |
| 26 | { |
| 27 | assert(std::accumulate(first, last, init) == x); |
| 28 | } |
| 29 | |
| 30 | template <class Iter> |
| 31 | void |
| 32 | test() |
| 33 | { |
| 34 | int ia[] = {1, 2, 3, 4, 5, 6}; |
| 35 | unsigned sa = sizeof(ia) / sizeof(ia[0]); |
| 36 | test(Iter(ia), Iter(ia), 0, 0); |
| 37 | test(Iter(ia), Iter(ia), 10, 10); |
| 38 | test(Iter(ia), Iter(ia+1), 0, 1); |
| 39 | test(Iter(ia), Iter(ia+1), 10, 11); |
| 40 | test(Iter(ia), Iter(ia+2), 0, 3); |
| 41 | test(Iter(ia), Iter(ia+2), 10, 13); |
| 42 | test(Iter(ia), Iter(ia+sa), 0, 21); |
| 43 | test(Iter(ia), Iter(ia+sa), 10, 31); |
| 44 | } |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | test<input_iterator<const int*> >(); |
| 49 | test<forward_iterator<const int*> >(); |
| 50 | test<bidirectional_iterator<const int*> >(); |
| 51 | test<random_access_iterator<const int*> >(); |
| 52 | test<const int*>(); |
| 53 | } |