Книга: Standard Template Library Programmer
fill_n
Разделы на этой странице:
fill_n
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
• OutputIterator is a model of Output Iterator.
• Size is an integral type (either signed or unsigned).
• T is a model of Assignable.
• T is convertible to a type in OutputIterator's set of value types.
Preconditions
• n >= 0.
• There is enough space to hold n values. 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);
See also
copy, fill, generate, generate_n, iota
- It’s All The Same, Just Different
- Using Graphical Configuration Tools
- Turn the Radio Up
- 10.7.1. DFS Interface
- 7.7.3 Interlocked, Two-Way Data Communication
- 7.2.5 Using Fill Prefixes
- Создание собственных методов DrawPie и FillPie
- fill
- uninitialized_fill
- uninitialized_fill_n
- 1.7.2 Letting Emacs Fill in the Blanks
- 2.7.3 Turning On Text Mode and Auto-Fill Mode Automatically