MyraMath
sum.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_UTILITY_SUM_H
7 #define MYRAMATH_UTILITY_SUM_H
8 
14 #include <vector>
15 
16 namespace myra {
17 
19 template<class T> T sum (const std::vector<T>& v)
20  {
21  T answer(0);
22  for (std::size_t i = 0; i < v.size(); ++i)
23  answer += v[i];
24  return answer;
25  }
26 
27 } // namespace myra
28 
29 #endif
Definition: syntax.dox:1
T sum(const std::vector< T > &v)
Returns cumulative sum. For example, cumsum({4,8,9,13}) = {0,4,12,21,34}.
Definition: sum.h:19