Namespaces
Variants

std::pmr::polymorphic_allocator<T>:: new_object

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
template < class U, class ... CtorArgs >
U * new_object ( CtorArgs && ... ctor_args ) ;
(C++20부터)

U 타입의 객체를 할당하고 생성합니다.

주어진 alloc std:: pmr :: polymorphic_allocator < T > 인 경우:

U* p = alloc.new_object<U>(std::forward<CtorArgs>(ctor_args)...);

다음과 동일합니다

U* p = alloc.allocate_object<U>();
try
{
    alloc.construct(p, std::forward<CtorArgs>(ctor_args)...);
}
catch (...)
{
    alloc.deallocate_object(p);
    throw;
}

목차

매개변수

ctor_args - U 의 생성자로 전달할 인수들

반환값

할당되고 생성된 객체에 대한 포인터.

참고 사항

이 함수는 완전 특수화된 allocator std:: pmr :: polymorphic_allocator <> 와 함께 사용하기 위해 도입되었지만, std:: pmr :: polymorphic_allocator < T > 에서 std:: pmr :: polymorphic_allocator < U > 로 재바인딩하고 allocate , construct , deallocate 를 개별적으로 호출하는 번거로움을 피하기 위한 단축키로 어떤 특수화에서도 유용할 수 있습니다.

U 가 추론되지 않으므로, 이 함수를 호출할 때 템플릿 인자로 제공해야 합니다.

예외

allocate_object 호출 또는 U 의 생성자에서 발생하는 모든 예외를 throw할 수 있습니다.

참고 항목

기본 리소스에서 정렬된 원시 메모리를 할당합니다
(public member function)
객체나 배열에 적합한 원시 메모리를 할당합니다
(public member function)
메모리를 할당합니다
(public member function)
[static]
할당자를 사용하여 초기화되지 않은 저장 공간을 할당합니다
( std::allocator_traits<Alloc> 의 public static member function)
메모리를 할당합니다
( std::pmr::memory_resource 의 public member function)