std::valarray::sum(3)
β¨ NAME β¨
std::valarray::sum β okay so this is literally std::valarray::sum, bestie. Welcome to the std::valarray::sum(3) page from the C++ Standard Libary manual β yes, that's the manual name, and yes, we're doing this. This whole page is about one member function with "add up the elements" energy. π
π Synopsis π
T sum() const;
It computes the sum of the elements. You can use this function only if operator+= is defined for type T. If the std::valarray is empty, the behavior is undefined β like, genuinely undefined, not a cute little edge case. The order in which the elements are processed by this function is unspecified. π«Ά
πΈ Parameters πΈ
(none) β literally no parameters, bestie. Not a single one. π
π Return value π
The sum of the elements. That's the whole return value. Iconic. β
π¦ Example π¦
Here's the code, and yes, run it:
#include <iostream>
#include <valarray>
int main()
{
std::valarray<int> a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::cout << a.sum() << '\n';
}
β Output β
55
π₯ See also π₯
applyβ applies a function to every element of a valarray (public member function)accumulateβ sums up or folds a range of elements (function template)
π cute little sign-off: this page is from cppreference.com, dated 2024.06.10, and it's the std::valarray::sum(3) entry. slay, bye bestie π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms