IT lexicon › Programming › C++ ranges

C++ ranges

Programming På svenska → Updated: 2026-07-29

C++20's overhaul of the standard algorithms: a collection is passed as one object instead of two iterators, and transformations chain together with a pipe.

The old style required writing std::sort(v.begin(), v.end()) and gave you no compiler help if the two iterators came from different containers. With ranges it becomes std::ranges::sort(v). The bigger novelty is views: lazy, non-owning adaptors that compose — v | views::filter(even) | views::transform(square) | views::take(5) walks the collection once without creating any intermediate vectors. The foundation is Eric Niebler's range-v3 library. The complaints concern compile times, error messages that stay hard to read even with concepts, and the fact that C++20 shipped without ranges::to, making it needlessly awkward to get an actual container back. That arrived in C++23.

← Back to the lexicon