|  |  |  | 
| Category: algorithms |  | Component type: function | 
Prototype
template <class OutputIterator, class Size, class T>
OutputIterator fill_n(OutputIterator first, Size n, const T& value);
Description
Fill_n assigns the value value to every element in the range [first, first+n). That is, for every iterator i in [first, first+n), it performs the assignment *i = value. The return value is first + n. 
Definition
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h. 
Requirements on types
- 
OutputIteratoris a model of OutputIterator.
- 
Sizeis an integral type (either signed or unsigned).
- 
Tis a model of Assignable.
- 
Tis convertible to a type inOutputIterator's set of value types.
Preconditions
- 
n >= 0.
- 
There is enough space to hold nvalues. That is,[first, first+n)is a valid range.
Complexity
Linear. Fill_n performs exactly n assignments. 
Example
Vector<double> V;
fill_n(back_inserter(V), 4, 137);
assert(V.size() == 4 && V[0] == 42 && V[1] == 42 && V[2] == 42 && V[3] == 42);
Notes
See also
copy, fill, generate, generate_n, iota