copy
Prototypetemplate <class InputIterator, class OutputIterator> OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result); DescriptionCopy copies elements from the range [first, last) to the range [result, result + (last - first)). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. [1] Generally, for every integer n from 0 to last - first, copy performs the assignment *(result + n) = *(first + n). Assignments are performed in forward order, i.e. in order of increasing n. [2]
The return value is DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.Requirements on types
Preconditions
ComplexityLinear. Exactlylast - first assignments are performed. ExampleVector<int> V(5); iota(V.begin(), V.end(), 1); List<int> L(V.size()); copy(V.begin(), V.end(), L.begin()); assert(equal(V.begin(), V.end(), L.begin())); Notes[1] Note the implications of this.Copy cannot be used to insert elements into an empty Container : it overwrites elements, rather than inserting elements. If you want to insert elements into a Sequence, you can either use its insert member function explicitly, or else you can use copy along with an insert_iterator adaptor.
[2] The order of assignments matters in the case where the input and output ranges overlap : See alsocopy_backward, copy_n | |||||||

