Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

generate, generate_n


Algorithm

Summary

Initialize a container with values produced by a value-generator class.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>

template <class ForwardIterator, class Generator>
  void generate(ForwardIterator first, ForwardIterator last,
                Generator gen);

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

Description

A value-generator function returns a value each time it is invoked. The algorithms generate and generate_n initialize (or reinitialize) a sequence by assigning the return value of the generator function gen to all the elements designated by iterators in the range [first, last) or [first, first + n). 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 there are at least n elements following first, unless first is an insert iterator.

Complexity

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

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

Function Objects



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998