What are C++20 Ranges, and how do they differ from traditional iterator-based algorithms?

Last updated 21 June 2026

  • Ranges treat a sequence (anything with begin/end) as one object, so algorithms take the container directly: std::ranges::sort(v) instead of iterator pairs. This prevents mismatched begin/end bugs.

  • Views like views::filter and views::transform are lazy and chain with |, computing on demand without intermediate containers. Projections (e.g. &Person::age) operate on members without lambdas.

  • Costs: heavier compile times, trickier debugging of view types, and iterator invalidation rules still apply.

  • https://pvs-studio.com/en/blog/posts/cpp/1193/
All C++ interview questions