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 // template <InputIterator Iter, MoveConstructible T, 12 // Callable<auto, const T&, Iter::reference> BinaryOperation> 13 // requires HasAssign<T, BinaryOperation::result_type> 14 // && CopyConstructible<BinaryOperation> 15 // T 16 // accumulate(Iter first, Iter last, T init, BinaryOperation binary_op); 17 18 #include <numeric> 19 #include <functional> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "test_iterators.h" 24 25 template <class Iter, class T> 26 void 27 test(Iter first, Iter last, T init, T x) 28 { 29 assert(std::accumulate(first, last, init, std::multiplies<T>()) == x); 30 } 31 32 template <class Iter> 33 void 34 test() 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 48 int main(int, char**) 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 return 0; 57 } 58