August 2012
Intermediate to advanced
976 pages
30h 17m
English
A number of the algorithms read, but never write to, the elements in their input range. The find function is one such algorithm, as is the count function we used in the exercises for § 10.1 (p. 378).
Another read-only algorithm is accumulate, which is defined in the numeric header. The accumulate function takes three arguments. The first two specify a range of elements to sum. The third is an initial value for the sum. Assuming vec is a sequence of integers, the following
// sum the elements in vec starting the summation with the value 0int sum = accumulate(vec.cbegin(), vec.cend(), 0);
sets sum equal to the sum of ...
Read now
Unlock full access