Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

fill, fill_n


Algorithm

Summary

Initializes a range with a given value.

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

None

Synopsis

#include <algorithm>
template <class ForwardIterator, class T>
  void fill(ForwardIterator first, ForwardIterator last,
            const T& value);

template <class OutputIterator, class Size, class T>
  void fill_n(OutputIterator first, Size n, const T& value);

Description

The fill and fill_n algorithms are used to assign a value to the elements in a sequence. fill assigns the value to all the elements designated by iterators in the range [first, last).

The fill_n algorithm assigns the value to all the elements designated by iterators in the range [first, first + n). fill_n assumes that there are at least n elements following first, unless first is an insert iterator.

Type T must be Assignable, and Size must be convertible to an integral type.

Complexity

fill makes exactly last - first assignments, and fill_n makes exactly n assignments.

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.



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