generate_n
Replaces n elements with the result of an operation
Definition
The generate_n() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class OutputIterator, class Diff, class Generator >
void generate_n(
OutputIterator first,
Diff count,
Generator gen
);Parameters:
| Parameter | Description |
| first | An output iterator addressing the position of first element in the range to which values are to be assigned |
| count | A signed or unsigned integer type specifying the number of elements to be assigned a value by the generator function |
| gen | A function object that is called with no arguments that is used to generate the values to be assigned to each of the elements in the range |
Description
The Generate_n algorithm does the same thing as http://www.codecogs.com/reference/computing/stl/algorithms/modifying/generate.php?showv=1"generate" but for n elements starting at first.
Return Value
None.
Complexity
The complexity is linear; count calls to the generator being required.
References
See Also
- http://www.codecogs.com/reference/computing/stl/algorithms/modifying/copy.php"copy"
- http://www.codecogs.com/reference/computing/stl/algorithms/modifying/fill.php"fill"
- http://www.codecogs.com/reference/computing/stl/algorithms/modifying/fill_n.php"fill_n"
- http://www.codecogs.com/reference/computing/stl/algorithms/modifying/generate.php"generate"
CodeCogs®