0Pricing
C++ Academy · Lesson

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 = 15

All lessons in this course

  1. Non-Modifying Algorithms find count all_of
  2. Modifying transform copy_if replace
  3. Sorting and Partitioning sort stable_partition
  4. Numeric Algorithms accumulate reduce transform_reduce
← Back to C++ Academy