Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) std::rotate_copy

 

std::rotate_copy is an STL algorithm to rotate-copy a container to another container.

 

#include <algorithm>
#include <cassert>
#include <vector>

int main()
{
  std::vector<int> v;
  v.push_back(0);
  v.push_back(1);
  v.push_back(2);
  std::vector<int> w;
  //Rotate-copy and let v[1] be the new w[0]
  //(and v[2] be w[1])
  //(and v[0] be w[2])
  std::rotate_copy(v.begin(),v.begin()+1,v.end(),std::back_inserter(w));
  assert(w[0]==1);
  assert(w[1]==2);
  assert(w[2]==0);
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict