std::copy_backward (3) - Linux Manuals
std::copy_backward: std::copy_backward
NAME
std::copy_backward - std::copy_backward
Synopsis
Defined in header <algorithm>
template< class BidirIt1, class BidirIt2 > (until C++20)
BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last );
template< class BidirIt1, class BidirIt2 > (since C++20)
constexpr BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last );
Copies the elements from the range, defined by [first, last), to another range ending at d_last. The elements are copied in reverse order (the last element is copied first), but their relative order is preserved.
The behavior is undefined if d_last is within (first, last]. std::copy must be used instead of std::copy_backward in that case.
Parameters
first, last - the range of the elements to copy
d_last - end of the destination range..
Type requirements
-
BidirIt must meet the requirements of LegacyBidirectionalIterator.
Return value
iterator to the last element copied.
Complexity
Exactly last - first assignments.
Notes
When copying overlapping ranges, std::copy is appropriate when copying to the left (beginning of the destination range is outside the source range) while std::copy_backward is appropriate when copying to the right (end of the destination range is outside the source range).
Possible implementation
Example
// Run this code
Output:
See also
copy
copy_if copies a range of elements to a new location
(C++11)