跳到主要内容

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

// 1)
polymorphic_allocator() noexcept;
// 2)
polymorphic_allocator( const polymorphic_allocator& other ) = default;
// 3)
template< class U >
polymorphic_allocator( const polymorphic_allocator<U>& other ) noexcept;
// 4)
polymorphic_allocator( std::pmr::memory_resource* r );

构造一个新的 polymorphic_allocator。

  1. 使用 std::pmr::get_default_resource() 的返回值作为底层内存资源来构造一个 polymorphic_allocator。
    2-3) 使用 other.resource() 作为底层内存资源来构造一个 polymorphic_allocator。
  2. 使用 r 作为底层内存资源来构造一个 polymorphic_allocator。此构造函数提供从 std::pmr::memory_resource* 的隐式转换。

参数

other - 要从中复制的另一个 polymorphic_allocator
r - 要使用的内存资源指针。不能为空。

异常

  1. 不抛出任何异常。

备注

使用 polymorphic_allocator 复制容器不会调用分配器的复制构造函数。相反,新容器将使用 select_on_container_copy_construction 的返回值(一个默认构造的 polymorphic_allocator)作为其分配器。

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

// 1)
polymorphic_allocator() noexcept;
// 2)
polymorphic_allocator( const polymorphic_allocator& other ) = default;
// 3)
template< class U >
polymorphic_allocator( const polymorphic_allocator<U>& other ) noexcept;
// 4)
polymorphic_allocator( std::pmr::memory_resource* r );

构造一个新的 polymorphic_allocator。

  1. 使用 std::pmr::get_default_resource() 的返回值作为底层内存资源来构造一个 polymorphic_allocator。
    2-3) 使用 other.resource() 作为底层内存资源来构造一个 polymorphic_allocator。
  2. 使用 r 作为底层内存资源来构造一个 polymorphic_allocator。此构造函数提供从 std::pmr::memory_resource* 的隐式转换。

参数

other - 要从中复制的另一个 polymorphic_allocator
r - 要使用的内存资源指针。不能为空。

异常

  1. 不抛出任何异常。

备注

使用 polymorphic_allocator 复制容器不会调用分配器的复制构造函数。相反,新容器将使用 select_on_container_copy_construction 的返回值(一个默认构造的 polymorphic_allocator)作为其分配器。