Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |memory‎ |polymorphic allocator
       
       
      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*)
      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);
      (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

      [edit]Parameters

      ctor_args - the arguments to forward to the constructor ofU

      [edit]Return value

      A pointer to the allocated and constructed object.

      [edit]Notes

      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.

      [edit]Exceptions

      May throw any exceptions thrown by the call toallocate_object or the constructor ofU.

      [edit]See also

      allocate raw aligned memory from the underlying resource
      (public member function)[edit]
      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 ofstd::allocator_traits<Alloc>)[edit]
      allocates memory
      (public member function ofstd::pmr::memory_resource)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/polymorphic_allocator/new_object&oldid=173022"

      [8]ページ先頭

      ©2009-2025 Movatter.jp