Which header provides ranges and how do you use range algorithms?
Short answer
Ranges live in (views/adaptors) and (the std::ranges:: algorithm overloads). You call algorithms in the std::ranges namespace passing a whole range, and build view pipelines with std::views::. Support requires a C++20-capable compiler and standard library.
Advertisement
AModel answer
Ranges live in <ranges> (views/adaptors) and <algorithm> (the std::ranges:: algorithm overloads). You call algorithms in the std::ranges namespace passing a whole range, and build view pipelines with std::views::. Support requires a C++20-capable compiler and standard library.
#include <ranges>
#include <algorithm>
std::ranges::for_each(v, [](int x){ /*...*/ });Real-world example
Adopting <ranges> lets the team write std::ranges algorithms and view pipelines across the codebase.
Likely follow-ups
- Which headers are needed? | What namespace holds the algorithms?
Related topics