Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit c8d5fec1f6.
PrevUpHomeNext

Class template polymorphic_allocator

boost::container::pmr::polymorphic_allocator

Synopsis

// In header: <boost/container/pmr/polymorphic_allocator.hpp>

template<typename T> 
class polymorphic_allocator {
public:
  // types
  typedef T value_type;

  // construct/copy/destruct
  polymorphic_allocator() noexcept;
  polymorphic_allocator(memory_resource *) noexcept;
  polymorphic_allocator(const polymorphic_allocator &) noexcept;
  template<typename U> 
    polymorphic_allocator(const polymorphic_allocator< U > &) noexcept;
  polymorphic_allocator & operator=(const polymorphic_allocator &) noexcept;

  // public member functions
  T * allocate(size_t);
  void deallocate(T *, size_t) noexcept;
  template<typename U, class ... Args> void construct(U *, Args &&...);
  template<typename U> void destroy(U *);
  polymorphic_allocator select_on_container_copy_construction() const noexcept;
  memory_resource * resource() const noexcept;
};

Description

A specialization of class template polymorphic_allocator conforms to the Allocator requirements. Constructed with different memory resources, different instances of the same specialization of 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.

polymorphic_allocator public construct/copy/destruct

  1. polymorphic_allocator() noexcept;

    Effects: Sets m_resource to get_default_resource().

  2. polymorphic_allocator(memory_resource * r) noexcept;

    Requires: r is non-null.

    Effects: Sets m_resource to r.

    Throws: Nothing

    Notes: This constructor provides an implicit conversion from memory_resource*.

  3. polymorphic_allocator(const polymorphic_allocator & other) noexcept;

    Effects: Sets m_resource to other.resource().

  4. template<typename U> 
      polymorphic_allocator(const polymorphic_allocator< U > & other) noexcept;

    Effects: Sets m_resource to other.resource().

  5. polymorphic_allocator & 
    operator=(const polymorphic_allocator & other) noexcept;

    Effects: Sets m_resource to other.resource().

polymorphic_allocator public member functions

  1. T * allocate(size_t n);

    Returns: Equivalent to static_cast<T*>(m_resource->allocate(n * sizeof(T), alignof(T))).

  2. void deallocate(T * p, size_t n) noexcept;

    Requires: p was allocated from a memory resource, x, equal to *m_resource, using x.allocate(n * sizeof(T), alignof(T)).

    Effects: Equivalent to m_resource->deallocate(p, n * sizeof(T), alignof(T)).

    Throws: Nothing.

  3. template<typename U, class ... Args> void construct(U * p, Args &&... args);

    Requires: Uses-allocator construction of T with allocator *this and constructor arguments std::forward<Args>(args)... is well-formed. [Note: uses-allocator construction is always well formed for types that do not use allocators. - end note]

    Effects: Construct a T object at p by uses-allocator construction with allocator *this and constructor arguments std::forward<Args>(args)....

    Throws: Nothing unless the constructor for T throws.

  4. template<typename U> void destroy(U * p);

    Effects: p->~U().

  5. polymorphic_allocator select_on_container_copy_construction() const noexcept;

    Returns: Equivalent to polymorphic_allocator().

  6. memory_resource * resource() const noexcept;

    Returns: m_resource.


PrevUpHomeNext