Numeric Algorithms accumulate reduce transform_reduce
Aggregate numeric ranges with accumulate, reduce, and parallel-friendly transform_reduce.
The <numeric> Header
Numeric algorithms operate on ranges of numbers. They live in <numeric>.
std::accumulate
The classic reduction. Sums by default — pass a custom binary operation for other reductions.
#include <numeric>
std::vector<int> v = {1, 2, 3, 4, 5};
int sum = std::accumulate(v.begin(), v.end(), 0);
// sum = 15All lessons in this course
- Non-Modifying Algorithms find count all_of
- Modifying transform copy_if replace
- Sorting and Partitioning sort stable_partition
- Numeric Algorithms accumulate reduce transform_reduce