move
move (범위 이동 복사)
범위의 요소를 목적지로 이동(move)하는 알고리즘이에요. <algorithm> 헤더에 있어요.
출처: cppreference
본문
move는 범위 [first, last)의 요소를 이동 생성/대입으로 목적지 d_first에 옮겨요.
template< class InputIt, class OutputIt >
OutputIt move( InputIt first, InputIt last, OutputIt d_first );
- 반환 값: 마지막 이동 후 다음 반복자.
- 복잡도:
last - first에 정확히 비례.
d_first가 소스 범위 안에 있으면 미정의 동작이에요(겹치면 move_backward 사용).
std::vector<std::string> src{"a", "b", "c"};
std::vector<std::string> dst(3);
std::move(src.begin(), src.end(), dst.begin());
// dst == {"a","b","c"}, src는 이동된 문자열들은 지정된-그러나-미지정 상태
이름이 혼동되기 쉬운데, std::move는 범위를 이동하는 알고리즘이고, <utility>의 std::move(캐스트)와는 다르다는 점을 기억하세요. 서로 다른 함수예요.