|Category: algorithms ||Component type: function |
template <class ForwardIterator, class T>
void fill(ForwardIterator first, ForwardIterator last, const T& value);
Fill assigns the value
value to every element in the range
[first, last). That is, for every iterator
[first, last), it performs the assignment
*i = value.
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.
Requirements on types
[first, last) is a valid range.
Fill performs exactly
last - first assignments.
fill(V.begin(), V.end(), 137);
assert(V == 137 && V == 137 && V == 137 && V == 137);
 The reason that
fill requires its argument to be a mutable ForwardIterator, rather than merely an OutputIterator, is that it uses a range
[first, last) of iterators. There is no sensible way to describe a range of OutputIterator, because it is impossible to compare two OutputIterator for equality. The
fill_n algorithm does have an interface that permits use of an OutputIterator.