Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::copy_backward

 

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::reverseto 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(v.begin(),v.end(),w.end());

  assert(w[0] == 0);
  assert(w[1] == 1);
  assert(w[2] == 1);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict