ranges_uninitialized_copy

ranges_uninitialized_copy (ranges::uninitialized_copy)

<memory> 헤더에 정의되어 있어요. 소스 범위의 요소들을 초기화되지 않은 대상 저장 공간에 복사해 구성해요. std::uninitialized_copy의 ranges 버전(니블로이드, niebloid)이에요. C++20부터 도입됐어요.

출처: cppreference

본문

호출 시그니처:

template< std::input_iterator I, std::sentinel_for<I> S1,
          /*nothrow-forward-iterator*/ O, /*nothrow-sentinel-for*/<O> S2 >
    requires std::constructible_from<std::iter_value_t<O>,
                                     std::iter_reference_t<I>>
uninitialized_copy_result<I, O>
    uninitialized_copy( I ifirst, S1 ilast, O ofirst, S2 olast );   // (1) since C++20, constexpr since C++26

template< ranges::input_range IR, /*nothrow-forward-range*/ OR >
    requires std::constructible_from<ranges::range_value_t<OR>,
                                     ranges::range_reference_t<IR>>
uninitialized_copy_result<ranges::borrowed_iterator_t<IR>,
                          ranges::borrowed_iterator_t<OR>>
    uninitialized_copy( IR&& in_r, OR&& out_r );   // (2) since C++20, constexpr since C++26

template< /*execution-policy*/ Ep, std::forward_iterator I, std::sentinel_for<I> S1,
          /*nothrow-forward-iterator*/ O, /*nothrow-sentinel-for*/<O> S2 >
    requires std::constructible_from<std::iter_value_t<O>,
                                     std::iter_reference_t<I>>
uninitialized_copy_result<I, O>
    uninitialized_copy( Ep&& policy, I ifirst, S1 ilast, O ofirst, S2 olast );  // (3) since C++26

소스 범위 [ifirst, ilast)를 대상 범위 [ofirst, olast)에 초기화해 복사해요. 각 대상 요소는 std::construct_at으로 구성돼요.

  • (1) 반복자·센티널 쌍.
  • (2) 범위 쌍.
  • (3) 실행 정책 policy에 따른 병렬 버전. (C++26)

반환값

{in_last, out_last} 형태의 uninitialized_copy_result를 돌려줘요. 복사한 마지막 입력·출력 반복자를 나타내요.

std::byte* buf = raw_storage...
T* dest = /* 초기화되지 않은 저장 공간 */;
std::ranges::uninitialized_copy(src.begin(), src.end(), dest, dest + src.size());

더 알아보기 (Learn more)

cppreference