boost::rotate_copy

References

Headers

boost::rotate_copy is available by including any of the following headers:

  • boost/range/algorithm/rotate_copy.hpp or
  • boost/range/algorithm.hpp

Examples

rotate_copy.cpp

#include <iostream>
#include <vector>
#include <boost/range/algorithm.hpp>

int main() {
    std::vector<int> vec = {1, 2, 3, 4, 5};
    std::vector<int> output;

    // Copies a rotated input range to an output iterator.
    // Returns an iterator to the end of the output range.
    boost::rotate_copy(vec, vec.begin() + 2, std::back_inserter(output));

    std::cout << "input vector after rotate_copy(): ";
    boost::range::copy(vec, std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;

    std::cout << "output vector after rotate_copy(): ";
    boost::range::copy(output, std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;
    return 0;
}

Output:

input vector after rotate_copy(): 1 2 3 4 5 
output vector after rotate_copy(): 3 4 5 1 2

 

Boost Range for Humans

This reference is part of Boost Range for Humans. Click the link to the overview.