reverse_copy

reverse_copy (뒤집어 복사)

범위를 뒤집은 결과를 새 목적지에 복사하는 알고리즘이에요. 원본은 그대로 두고요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

reverse_copy[first, last)를 뒤집은 순서로 d_first에 복사해요.

template< class BidirIt, class OutputIt >
OutputIt reverse_copy( BidirIt first, BidirIt last, OutputIt d_first );
  • 반환 값: 마지막으로 복사한 원소 다음 반복자.
  • 복잡도: last - first에 정확히 비례.
std::vector<int> v{1, 2, 3, 4};
std::vector<int> out(4);
std::reverse_copy(v.begin(), v.end(), out.begin());
// out == {4,3,2,1}, v는 그대로

원본을 보존하며 뒤집은 결과를 새 컨테이너에 담을 때 써요.

더 알아보기 (Learn more)

cppreference