std::move_backward (3) - Linux Manuals
std::move_backward: std::move_backward
NAME
std::move_backward - std::move_backward
Synopsis
Defined in header <algorithm>
template< class BidirIt1, class BidirIt2 > (since C++11)
BidirIt2 move_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last ); (until C++20)
template< class BidirIt1, class BidirIt2 > (since C++20)
constexpr BidirIt2 move_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last );
Moves the elements from the range [first, last), to another range ending at d_last. The elements are moved in reverse order (the last element is moved first), but their relative order is preserved.
The behavior is undefined if d_last is within (first, last]. std::move must be used instead of std::move_backward in that case.
Parameters
first, last - the range of the elements to move
d_last - end of the destination range
Type requirements
-
BidirIt1, BidirIt2 must meet the requirements of LegacyBidirectionalIterator.
Return value
Iterator in the destination range, pointing at the last element moved.
Complexity
Exactly last - first move assignments.
Possible implementation
Notes
When moving overlapping ranges, std::move is appropriate when moving to the left (beginning of the destination range is outside the source range) while std::move_backward is appropriate when moving to the right (end of the destination range is outside the source range).
Example
// Run this code