C++ Algorithms and Ranges

C++ Algorithms and Ranges

Classic STL algorithms, numeric algorithms, projections, iterators, and modern range views in one focused reference.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

C++ Algorithms and Ranges

Classic algorithm families from <algorithm>

Numeric algorithms from <numeric>

Iterator and projection concepts

std::ranges::sort(users, std::greater<>{}, &User::score);

Common view adaptors from <ranges>

Rules that matter in practice

Example in practice

#include <ranges>
#include <vector>

int main() {
    std::vector<int> values{1, 2, 3, 4};
    auto even = values | std::views::filter([](int value) { return value % 2 == 0; });
    return *even.begin();
}