Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

copy, copy_backward


Algorithm

Summary

Copies a range of elements.

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

None

Synopsis

#include <algorithm>
template <class InputIterator, class OutputIterator>
 OutputIterator copy(InputIterator first, 
                     InputIterator last,
                     OutputIterator result);
template <class BidirectionalIterator1, 
          class BidirectionalIterator2>
 BidirectionalIterator2
  copy_backward(BidirectionalIterator1 first,
                BidirectionalIterator1 last,
                BidirectionalIterator2 result);

Description

The copy algorithm copies values from the range specified by [first, last) to the range specified by [result, result + (last - first)). copy can be used to copy values from one container to another, or to copy values from one location in a container to another location in the same container, as long as result is not within the range [first-last). copy returns result + (last - first). For each non-negative integer n < (last - first), copy assigns *(first + n) to *(result + n). The result of copy is undefined if result is in the range [first, last).

Unless result is an insert iterator, copy assumes that at least as many elements follow result as are in the range [first, last).

The copy_backward algorithm copies elements in the range specified by [first, last) into the range specified by [result - (last - first), result), starting from the end of the sequence (last-1) and progressing to the front (first). Note that copy_backward does not reverse the order of the elements, it simply reverses the order of transfer. copy_backward returns result - (last - first). You should use copy_backward instead of copy when last is in the range [result - (last - first), result). For each positive integer n <= (last - first), copy_backward assigns *(last - n) to *(result - n). The result of copy_backward is undefined if result is in the range [first, last).

Unless result is an insert iterator, copy_backward assumes that there are at least as many elements ahead of result as are in the range [first, last).

Complexity

Both copy and copy_backward perform exactly last - first 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