A specialization of class template
pmr::polymorphic_allocator
satisfies the
Cpp17Allocator requirements (Table
33)
. Constructed with different memory resources,
different instances of the same specialization of
pmr::polymorphic_allocator
can exhibit entirely different allocation behavior
. This runtime polymorphism allows objects that use
polymorphic_allocator
to behave as if they used different allocator types at run time
even though they use the same static allocator type
.
namespace std::pmr {
template<class Tp> class polymorphic_allocator {
memory_resource* memory_rsrc;
public:
using value_type = Tp;
polymorphic_allocator() noexcept;
polymorphic_allocator(memory_resource* r);
polymorphic_allocator(const polymorphic_allocator& other) = default;
template<class U>
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
polymorphic_allocator& operator=(const polymorphic_allocator& rhs) = delete;
[[nodiscard]] Tp* allocate(size_t n);
void deallocate(Tp* p, size_t n);
template<class T, class... Args>
void construct(T* p, Args&&... args);
template<class T1, class T2, class... Args1, class... Args2>
void construct(pair<T1, T2>* p, piecewise_construct_t,
tuple<Args1...> x, tuple<Args2...> y);
template<class T1, class T2>
void construct(pair<T1, T2>* p);
template<class T1, class T2, class U, class V>
void construct(pair<T1, T2>* p, U&& x, V&& y);
template<class T1, class T2, class U, class V>
void construct(pair<T1, T2>* p, const pair<U, V>& pr);
template<class T1, class T2, class U, class V>
void construct(pair<T1, T2>* p, pair<U, V>&& pr);
template<class T>
void destroy(T* p);
polymorphic_allocator select_on_container_copy_construction() const;
memory_resource* resource() const;
};
}