|
|
Member functions | ||||
(C++20/26*) | ||||
polymorphic_allocator::new_object (C++20) | ||||
Non-member functions | ||||
(until C++20) |
template<class U,class...CtorArgs> U* new_object( CtorArgs&&...ctor_args); | (since C++20) | |
Allocates and constructs an object of typeU
.
Givenalloc
is astd::pmr::polymorphic_allocator<T>:
U* p= alloc.new_object<U>(std::forward<CtorArgs>(ctor_args)...);
is equivalent to
U* p= alloc.allocate_object<U>();try{ alloc.construct(p,std::forward<CtorArgs>(ctor_args)...);}catch(...){ alloc.deallocate_object(p);throw;}
Contents |
ctor_args | - | the arguments to forward to the constructor ofU |
A pointer to the allocated and constructed object.
This function was introduced for use with the fully-specialized allocatorstd::pmr::polymorphic_allocator<>, but it may be useful in any specialization as a shortcut to avoid having to rebind fromstd::pmr::polymorphic_allocator<T> tostd::pmr::polymorphic_allocator<U>, and having to callallocate,construct, anddeallocate individually.
SinceU
is not deduced, it must be provided as a template argument when calling this function.
May throw any exceptions thrown by the call toallocate_object or the constructor ofU
.
(C++20) | allocate raw aligned memory from the underlying resource (public member function)[edit] |
(C++20) | allocates raw memory suitable for an object or an array (public member function)[edit] |
allocate memory (public member function)[edit] | |
[static] | allocates uninitialized storage using the allocator (public static member function of std::allocator_traits<Alloc> )[edit] |
allocates memory (public member function of std::pmr::memory_resource )[edit] |