Using ranges

Ranges are tied to views. We will examine them both in this section. We discussed STL containers and algorithms in Chapter 6, Digging into Data Structures and Algorithms in STL. They provide us with a generic approach to composing and working with collections of objects. As you already know, we use iterators a lot to loop over containers and work with their elements. Iterators are tools that allow us to have loose coupling between algorithms and containers.

For example, earlier, we applied count_if() to the vector, but count_if() is not aware of what container it is was applied to. Take a look at the following declaration of count_if():

template <typename InputIterator, typename UnaryPredicate>constexpr typename iterator_traits<InputIterator>::difference_type ...

Get Expert C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.