copy_backward
Prototypetemplate <class BidirectionalIterator1, class BidirectionalIterator2> BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result); DescriptionCopy_backward copies elements from the range [first, last) to the range [result - (last - first), result) [1]. That is, it performs the assignments *(result - 1) = *(last - 1), *(result - 2) = *(last - 2), and so on. Generally, for every integer n from 0 to last - first, copy_backward performs the assignment *(result - n - 1) = *(last - n - 1). Assignments are performed from the end of the input sequence to the beginning, 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(15); iota(V.begin(), V.end(), 1); copy_backward(V.begin(), V.begin() + 10, V.begin() + 15); Notes[1]Result is an iterator that points to the end of the output range. This is highly unusual: in all other STL algorithms that denote an output range by a single iterator, that iterator points to the beginning of the range.
[2] The order of assignments matters in the case where the input and output ranges overlap: See alsocopy, copy_n | |||||||

