memory_uninitialized_move_n

memory_uninitialized_move_n (std::uninitialized_move_n)

<memory> 헤더에 정의되어 있어요. 소스 범위의 처음 count개 요소를 대상 범위로 이동해 구성해요. C++17부터 도입됐어요.

출처: cppreference

본문

template< class InputIt, class Size, class NoThrowForwardIt >
std::pair<InputIt, NoThrowForwardIt>
    uninitialized_move_n( InputIt first, Size count, NoThrowForwardIt d_first );  // (1) since C++17, constexpr since C++26

template< class ExecutionPolicy, class ForwardIt, class Size, class NoThrowForwardIt >
std::pair<ForwardIt, NoThrowForwardIt>
    uninitialized_move_n( ExecutionPolicy&& policy, ForwardIt first, Size count, NoThrowForwardIt d_first );  // (2) since C++17
  • (1) 소스 범위의 처음 count개 요소를 d_first에서 시작하는 대상 범위로 이동해 구성해요. 각 대상 요소는 std::move된 소스 요소로 구성돼요. 초기화 중 예외가 발생하면 이미 구성된 객체들이 미지정 순서로 파괴돼요.
  • (2) (1)과 같지만 policy에 따라 실행돼요.

매개변수

  • first: 이동할 요소 범위의 시작
  • count: 이동할 요소 수
  • d_first: 대상 범위의 시작
  • policy: 사용할 실행 정책

반환값

{first + count, d_first + count} 형태의 std::pair. 마지막으로 이동·구성한 요소 다음의 반복자들.

무버를 이용해 초기화되지 않은 메모리에 객체를 이동 구성할 때 써요. 이동된 소스 요소는 유효하지만 미지정 상태로 남을 수 있어요.

std::vector<T> src = ...;
T* buf = ...;
auto [in_last, out_last] = std::uninitialized_move_n(src.begin(), src.size(), buf);

더 알아보기 (Learn more)

cppreference