All Numeric Algorithms
All Numeric Algorithms
A compact scan page for the main standard numeric algorithms from <numeric> and adjacent math-oriented facilities.
All Numeric Algorithms
A compact scan page for the main standard numeric algorithms from <numeric> and adjacent math-oriented facilities.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::accumulatestd::reducestd::transform_reducestd::inclusive_scanstd::exclusive_scanstd::transform_inclusive_scanstd::transform_exclusive_scanstd::adjacent_differencestd::inner_productstd::gcdstd::lcm<numeric>accumulate for ordered left folds when sequencing matters.reduce when parallel-friendly reduction semantics are acceptable.#include <numeric>
#include <vector>
int main() {
std::vector<int> values{5, 7, 2, 4};
std::vector<int> prefix(values.size());
std::inclusive_scan(values.begin(), values.end(), prefix.begin());
return prefix.back();
}
Scan algorithms are the right tool when each output depends on all earlier input, such as running totals, partial sums, or progressive limits.
accumulate when left-to-right order matters or the operation is not safely reorderablereduce when the operation is associative enough for parallel-friendly reduction semanticstransform_reduce when mapping and combining belong in one pass#include <numeric>
#include <vector>
int main() {
std::vector<int> values{1, 2, 3, 4};
auto prefix = std::vector<int>(values.size());
std::inclusive_scan(values.begin(), values.end(), prefix.begin());
return prefix.back();
}