Using ranges
Ranges represent a collection of objects or anything iterable abstractly. The simplest definition merely requires begin()
and end()
to exist on the range. Ranges may be categorized in a variety of ways, but the most crucial one is according to the abilities of its iterators.
Ranges are connected to views. In this chapter, we will look at them both. They give us a general approach to creating and managing groupings of items. We often use iterators to loop through containers and work with their elements, as you have already seen. Thanks to iterators, we can have a loose connection between algorithms and containers.
For example, earlier, we applied count_if()
to the vector, but count_if()
is not aware of what container it 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 count_if(InputIterator first, InputIterator...