Initializing a range
In the previous recipes, we explored the general standard algorithms for searching in a range and sorting a range. The algorithms library provides many other general algorithms, and among them are several that are intended for filling a range with values. In this recipe, you will learn what these algorithms are and how they should be used.
Getting ready
All the examples in this recipe use std::vector
. However, like all the general algorithms, the ones we will see in this recipe take iterators to define the bounds of a range and can therefore be used with any standard container, arrays, or custom types representing a sequence that have forward iterators defined.
Except for std::iota()
, which is available in the <numeric>
header, all the other algorithms are found in the <algorithm>
header.
How to do it...
To assign values to a range, use any of the following standard algorithms:
std::fill()
to assign a value to all...