valarray::sum

valarray::sum

T sum() const;

The member function returns the sum of all elements of *this, which must have nonzero length. If the length is greater than one, it adds values to the sum by applying operator+= between pairs of elements of class T.