uninitialized_construct_using_allocator — std::uninitialized_construct_using_allocator

uninitialized_construct_using_allocator — std::uninitialized_construct_using_allocator

std::uninitialized_construct_using_allocator는 초기화되지 않은 메모리 위치에 uses-allocator 생성 방식으로 T 타입 객체를 생성하는 함수예요. C++20에서 도입됐어요. <memory> 헤더에 제공돼요.

이미 확보한 원시 메모리(p)에 할당자 인식 타입을 안전하게 생성할 때 사용해요. 할당자 인식이라면 할당자를 올바르게 전달하고, 아니면 일반 생성자로 만든 뒤 포인터를 반환해요.

출처: cppreference

본문

std::uninitialized_construct_using_allocator는 초기화되지 않은 메모리 위치에 T 객체를 만들어요.

template<class T, class Alloc, class... Args>
constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);

p가 가리키는 초기화되지 않은 메모리 위치에 uses-allocator 생성을 통해 T 타입 객체를 생성하고, p를 반환해요. T가 할당자 인식 타입이면 uses_allocator_construction_args에 따라 할당자를 생성자 인자로 전달하고, 아니면 args...로 일반 생성자를 호출해요.

이렇게 생성된 객체는 사용 후 수명을 명시적으로 종료하는 등의 관리가 필요해요. 배치 생성(placement construction)의 할당자 인식 버전이라고 생각하면 돼요.

같이 보기

  • std::make_obj_using_allocator
  • std::uses_allocator_construction_args
  • std::uses_allocator

더 알아보기 (Learn more)

cppreference