Advancing from Abstract Ranges to the Ranges Library

Learn about the transition from the abstract concept of a range to the C++20 ranges library.

Traversing ranges using iterators

A range is an abstraction of a sequence of elements, delimited by two iterators (one to the first element of the sequence and one to the one-past-the-last element). Containers such as std::vector, std::list, and std::map are concrete implementations of the range abstraction. They have ownership of the elements, and they are implemented using various data structures, such as arrays, linked lists, or trees. The standard algorithms are generic. They are container agnostic. They know nothing about std::vector, std::list, or std::map. They handle range abstractions with the help of iterators. However, this has a shortcoming: we always need to retrieve a beginning and end iterator from a container. Here are some examples:

Get hands-on with 1200+ tech skills courses.