public member function
<valarray>
std::valarray::sum
Return sum of elements
operator+= to a copy of one element and all the other elements, in an unspecified order.If the valarray has a size of zero, it causes undefined behavior.
T shall support the calls to operator+=.
Parameters
noneReturn value
The sum of all the elements in the valarray.T is the template argument of valarray (the value type).
Example
|
|
Output:
Complexity
Depends on library implementation (operations may be parallelized).Iterator validity
No changes: Valid iterators, references and sub-arrays keep their validity.Data races
Both the valarray and its elements are accessed.Exception safety
If applying operator+= to element values throws an exception, it causes undefined behavior.If the valarray has a size of zero, it causes undefined behavior.
See also
- valarray::min
- Return smallest value (public member function)
- valarray::max
- Return greatest value (public member function)
- valarray operators
- Valarray operators (function)