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

copy(), copy_backward()

Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that copies a range of elements

Synopsis

#include <algorithm>

namespace std {
  template <class InputIterator, class OutputIterator>
  OutputIterator copy(InputIterator start, 
                      InputIterator finish,
                      OutputIterator result);
  template <class BidirectionalIterator1, 
            class BidirectionalIterator2>
  BidirectionalIterator2
  copy_backward(BidirectionalIterator1 start,
                BidirectionalIterator1 finish,
                BidirectionalIterator2 result);
}

Description

The copy() algorithm copies values from the range specified by [start, finish) to the range specified by [result, result + (finish - start)). copy() returns result + (finish - start). For each non-negative integer n < (finish - start), copy() assigns *(start + n) to *(result + n). The result of copy() is undefined if result is in the range [start, finish).

Unless result is an insert iterator, copy() assumes that all iterators in the range [result + (finish - start)] are dereferenceable.

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

Unless result is an insert iterator, copy_backward() assumes that all iterators in the range [result - (finish - start), result) are dereferenceable.

Complexity

Both copy() and copy_backward() perform exactly finish - start assignments.

Example

See Also

Algorithms, <algorithm>

Standards Conformance

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



Previous fileTop of DocumentContentsIndex pageNext file