Skip to content
C++

Algorithms

21 algorithm pages — sorting, searching, transforming, numeric, set operations, and parallel execution.

Binary Search

std::binary_search, lower_bound, upper_bound, equal_range and partition_point: logarithmic search over sorted ranges, with ranges variants, comparators and pitfalls.

Fold Operations

Reduce a range to a single value using std::accumulate, std::reduce, std::transform_reduce, and the C++23 ranges::fold family.

Heap Operations

Algorithms for creating, maintaining, querying, and sorting heap-ordered ranges in-place using random-access iterators.

Lexicographical Compare

std::lexicographical_compare and its C++20 siblings: dictionary-order comparison of two ranges, custom comparators, parallel overloads, and three-way results.

Min/Max Algorithms

Complete guide to std::min, std::max, std::minmax, clamp, and their range-element variants—signatures, version history, pitfalls, and idiomatic C++20 usage.

Modifying Sequence Algorithms

STL algorithms from <algorithm> that mutate a target range by copying, filling, generating, transforming, replacing, or rearranging elements.

Non-Modifying Sequence Algorithms

C++ non-modifying algorithms — for_each, count, count_if, any_of, all_of, none_of, find, find_if, mismatch, equal, and their C++20 ranges equivalents.

Numeric Algorithms — <numeric>

Complete reference for C++ numeric algorithms: accumulate, reduce, transform_reduce, prefix scans, gcd, lcm, midpoint, lerp, and parallel variants.

Parallel Algorithms (C++17)

C++17 execution policies for STL algorithms — par, par_unseq, reduce, transform_reduce, scan, thread safety, and platform requirements.

Partitioning Algorithms

Reorder, inspect, and copy elements based on a predicate with std::partition and its companion algorithms.

Permutation Algorithms

Generate and enumerate lexicographic permutations, check range equivalence, and randomly shuffle sequences using the C++ Standard Library.

Ranges & Views — Complete Reference

"C++20 ranges and views: range concepts, lazy view adaptors, composable pipelines, projections, and the pitfalls that bite experienced engineers."

Scan Operations

Prefix-sum algorithms in <numeric>: partial_sum (C++98) and the parallel-capable inclusive_scan, exclusive_scan, and transform variants added in C++17.

Searching Algorithms

C++ searching algorithms — std::find, binary_search, lower_bound, upper_bound, equal_range, search, and C++20 ranges equivalents with projections.

Set and Heap Algorithms

Set algorithms operating on sorted ranges and heap operations — multiset semantics, complexity guarantees, and C++20 ranges versions.

Sorting Algorithms

"C++ sorting: std::sort, std::stable_sort, std::partial_sort, std::nth_element, ranges variants, custom comparators, and strict weak ordering."

std::merge / std::inplace_merge

Merge two sorted ranges into a single sorted output range. Both std::merge and std::inplace_merge are stable and have been available since C++98.

std::sample

Select n elements uniformly at random without replacement from a population range, preserving their relative order.

STL Algorithms Overview

Complete guide to <algorithm> and std::ranges algorithms — sorting, searching, transforming, partitioning, and parallel execution.

Transforming and Mutating Algorithms

Deep reference for std::transform, for_each, copy, fill, generate, remove, rotate, and C++20 ranges equivalents with pitfalls and best practices.

Uninitialized Memory Algorithms

Low-level algorithms for constructing, copying, moving, and destroying objects in raw allocated storage, decoupling allocation from object lifetime management.