# **[](https://en.cppreference.com/w/cpp/header/ranges)** provides the ranges library (C++20): a new way to express algorithms that works on ranges directly instead of iterator pairs. Instead of `std::sort(v.begin(), v.end())`, you write `std::ranges::sort(v)`. Range adapters like `std::views::filter` compose transformations lazily. It's more expressive and composable than the classic iterator-based algorithms, but requires C++20 or later. ## Example This example sorts a vector and filters even numbers using range-based algorithms and views with the pipe operator. ```cpp // compile: g++ -std=c++20 -o rangesexample rangesexample.cpp // run: ./rangesexample // description: ranges library with views #include #include #include int main() { std::vector nums = {1, 2, 3, 4, 5}; std::ranges::sort(nums); auto evens = nums | std::views::filter([](int x) { return x % 2 == 0; }); for (int x : evens) { std::cout << x << " "; } std::cout << "\n"; return 0; } ```