1.accumulate:computes the sum of the elements in a specified range including some initial value by computing Successiv E partial sums or computes the result of successive partial results similarly obtained from using a specified binary opera tion other than the sum.
2 function prototypes (#include <numeric>)
Template<class Inputiterator, class type> type accumulate ( _first _last type _val ); Template<class Inputiterator, Class Type, class binaryoperation> Type Accumulate ( _first _last Type _val _binary_op );
3 parameters
-
_first
-
An-input iterator addressing the first element in the range to being summed or combined according to a specified binary opera tion.
-
_last
-
An input iterator addressing, the last element in the range, is summed or combined according to a specified binary Operat Ion that's one position beyond the final element actually included in the iterated accumulation.
-
_val
-
An initial value to which each element was in turn added or combined with according to a specified binary operation.
-
_binary_op
-
String sum = Accumulate (V.begin (), V.end (), String ("")); Each string element in V is linked, note that it must be a string ("") and cannot be "".
4 return value
The sum of _val and all the elements in the specified range for the first template function, or, for the second template F Unction, the result of applying the binary operation specified, instead of the sum operation, to (Partialresult, *iter ), where Partialresult is the result of previous applications of the operation and Iter are an iterator point ing to a element in the range.
5 examples
int sum = accumulate (Vec.begin (), Vec.end (), sum) sums the elements of the VEC and adds 42.
String sum = Accumulate (V.begin (), V.end (), String ("")); Each string element in V is linked, note that it must be a string ("") and cannot be "".
Generic algorithm One