Unlike algorithm fill_n, uninitialized_fill_n constructs the objects at destination, instead of just copying the value to them. This allows to obtain fully constructed copies into a range of uninitialized memory, such as a memory block obtained by a call to get_temporary_buffer or malloc.
The behavior of this function template is equivalent to:
| 1 2 3 4 5 6 7 |
|
Parameters
- first
- Forward iterators to the initial position in an unitialized sequence of at least n elements.
- n
- Number of elements to initialize
Size is expected to be a numeric type. - x
- Value to be used to fill the range.
Return value
noneExample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Output:
c++ rocks! c++ rocks! c++ rocks! |
Complexity
Linear: Constructs (copy constructor) as many objects as the number of elements in the range [first,last).See also
| fill_n | Fill sequence with value (function template) |
| uninitialized_copy | Copy block of memory (function template) |
| uninitialized_fill | Fill block of memory (function template) |
| get_temporary_buffer | Get block of temporary memory (function template) |
