ranges_uninitialized_default_construct

ranges_uninitialized_default_construct (ranges::uninitialized_default_construct)

<memory> 헤더에 정의되어 있어요. 범위의 객체들을 초기화되지 않은 저장 공간에 기본 생성(default construct)해요. std::uninitialized_default_construct의 ranges 버전(니블로이드, niebloid)이에요. C++20부터 도입됐어요.

출처: cppreference

본문

호출 시그니처:

template< /*nothrow-forward-iterator*/ I, /*nothrow-sentinel-for*/<I> S >
    requires std::default_initializable<std::iter_value_t<I>>
I uninitialized_default_construct( I first, S last );   // (1) since C++20, constexpr since C++26

template< /*nothrow-forward-range*/ R >
    requires std::default_initializable<ranges::range_value_t<R>>
ranges::borrowed_iterator_t<R>
    uninitialized_default_construct( R&& r );   // (2) since C++20, constexpr since C++26

template< /*execution-policy*/ Ep, /*nothrow-random-access-iterator*/ I,
          /*nothrow-sentinel-for*/<I> S >
    requires std::default_initializable<std::iter_value_t<I>>
I uninitialized_default_construct( Ep&& policy, I first, S last );  // (3) since C++26

[first, last) 범위에 std::construct_at(std::addressof(*it))로 객체를 기본 생성해요. 예외가 발생하면 이미 구성된 요소들이 역순으로 파괴돼요.

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

반환값

마지막으로 구성한 요소 다음의 반복자.

T* buf = ...;
std::ranges::uninitialized_default_construct(buf, buf + 10);

더 알아보기 (Learn more)

cppreference