algorithm_rotate_copy
algorithm_rotate_copy (회전 복사)
std::rotate_copy는 소스 범위를 회전한 결과를 목적지 범위에 복사해요. 원본은 변경하지 않아요.
출처: cppreference
본문
std::rotate_copy는 소스 범위 [first, last)를 회전한 듯한 순서로 복사해요. [middle, last)의 요소들을 먼저 복사하고 [first, middle)의 요소들을 이어서 복사해요. <algorithm> 헤더에 정의되어 있어요.
template< class ForwardIt, class OutputIt >
OutputIt rotate_copy( ForwardIt first, ForwardIt middle, ForwardIt last,
OutputIt d_first );
병렬 실행 정책을 받는 오버로드도 있어요.
반환값 (Return value)
복사된 마지막 요소 다음의 반복자예요.
복잡도 (Complexity)
정확히 std::distance(first, last)번의 배정이 필요해요.
예제 (Example)
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
std::vector<int> src{1, 2, 3, 4, 5, 6};
std::vector<int> out;
std::rotate_copy(src.begin(), src.begin() + 2, src.end(),
std::back_inserter(out));
for (int x : out) std::cout << x << ' ';
std::cout << '\n';
}
출력:
3 4 5 6 1 2