Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

generate(), generate_n()

Library:  Algorithms


Local Index

No Entries


Algorithm that assigns each element in a range a value produced by repeated application of the given function object


#include <algorithm>

namespace std {
  template <class ForwardIterator, class Generator>
  void generate(ForwardIterator start, ForwardIterator finish,
                Generator gen);

  template <class OutputIterator, class Size, class Generator>
  void generate_n(OutputIterator start, Size n,
                  Generator gen);


A value-generator function returns a value each time it is invoked. The algorithms generate() and generate_n() assign each element in the sequence [start, finish) or [start, start + n) the return value of the generator function gen(). The function gen() takes no arguments. (gen() can be a function or a class with an operator() defined that takes no arguments.)

generate_n() assumes that all iterators in the range [start, start + n] are dereferenceable, unless start is an insert iterator.


The generate() and generate_n() algorithms invoke gen() and assign its return value exactly finish - start (or n) times.


See Also

Function Objects

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.2.6

Previous fileTop of DocumentContentsIndex pageNext file