template <class ForwardIterator, class OutputIterator>
OutputIterator rotate_copy (ForwardIterator first, ForwardIterator start,
ForwardIterator last, OutputIterator result);
Return type : An output iterator pointing to the end of the copied range.
Working:The rotate_copy( ) function takes 4 parameters, 'first' , 'last' , 'start' and result.Forward iterators to the initial and final positions of the range to be copy-rotated. Forward iterator pointing to the element within the range [first,last)
that is copied to the first position in the range.Output iterator to the initial position of the range where the reversed range is stored.
Implementation:
#include <iostream> // std::cout
#include <algorithm> // std::rotate_copy
#include <vector> // std::vector
int main () {
std::vector<int> element {1,2,3,4,5,6,7,8,9};
std::vector<int> element_size (element.size());
std::rotate_copy(element.begin(),element.begin()+3,element.end(),element_size.begin());
std::cout << "Element contains:";
for (std::vector<int>::iterator it=element_size.begin(); it!=element_size.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
Output:
Element contains: 4 5 6 7 8 9 1 2 3
Comments