(C++) std::copy_backward
January 8, 2018 ยท View on GitHub
std::copy_backward is an STL algorithm to copy a container to the end of another. std::copy_backward does not reverse the order of the copied container, use std::reverse to do so.
#include <algorithm>
#include <cassert>
#include <vector>
int main()
{
std::vector<int> v;
v.push_back(1);
v.push_back(1);
std::vector<int> w;
w.push_back(0);
w.push_back(0);
w.push_back(0);
//Copy v to w's end
std::copy_backward(std::begin(v),std::end(v),std::end(w));
assert(w[0] == 0);
assert(w[1] == 1);
assert(w[2] == 1);
}