(C++) std::move\_backward
January 11, 2018 · View on GitHub
(C++) std::move_backward
std::move_backward is a C++11 STL algorithm to std::move elements from a container to another container. This copying is done in reverse, but the order is preserved.
#include <algorithm> #include <cassert> #include <vector> int main() { ///Create a std::vector to modify std::vector<int> v = { 0,1,2,3,4,5,6,7,8,9 }; ///Create a std::vector to move const std::vector<int> w = { 66,77,88 }; ///Move w to v, w's last element will be the 1-but-last in v std::move_backward(w.begin(),w.end(),v.end() - 1); assert(v == std::vector<int>( { 0,1,2,3,4,5,66,77,88,9 } )); }