Boost C++ Libraries 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 develop branch, built from commit c5994560ca.

Class template resource_adaptor_imp



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

template<typename Allocator> 
class resource_adaptor_imp : public boost::container::pmr::memory_resource {
  // types
  typedef Allocator allocator_type;

  // construct/copy/destruct
  resource_adaptor_imp(const resource_adaptor_imp &);
  resource_adaptor_imp(resource_adaptor_imp &&);
  explicit resource_adaptor_imp(const Allocator &);
  explicit resource_adaptor_imp(Allocator &&);
  resource_adaptor_imp & operator=(const resource_adaptor_imp &);
  resource_adaptor_imp & operator=(resource_adaptor_imp &&);

  // public member functions
  allocator_type & get_allocator();
  const allocator_type & get_allocator() const;

  // protected member functions
  virtual void * do_allocate(std::size_t, std::size_t);
  virtual void do_deallocate(void *, std::size_t, std::size_t);
  virtual bool do_is_equal(const memory_resource &) const noexcept;

  // private member functions
  void * priv_aligned_alloc(std::size_t, std::size_t);
  void priv_aligned_dealloc(void *, std::size_t, std::size_t);

  // private static functions
  static void * priv_bookeeping_addr_from_aligned_ptr(void *);
  static std::size_t priv_extra_bytes_for_overalignment(std::size_t);
  static std::size_t priv_guaranteed_allocator_alignment();


An instance of resource_adaptor<Allocator> is an adaptor that wraps a memory_resource interface around Allocator. In order that resource_adaptor<X<T>> and resource_adaptor<X<underline>> are the same type for any allocator template X and types T and U, resource_adaptor<Allocator> is rendered as an alias to this class template such that Allocator is rebound to a char value type in every specialization of the class template. The requirements on this class template are defined below. In addition to the Allocator requirements, the parameter to resource_adaptor shall meet the following additional requirements:</underline>



resource_adaptor_imp public construct/copy/destruct

  1. resource_adaptor_imp();

    Effects: Default constructs m_alloc.

  2. resource_adaptor_imp(const resource_adaptor_imp & other);

    Effects: Copy constructs m_alloc.

  3. resource_adaptor_imp(resource_adaptor_imp && other);

    Effects: Move constructs m_alloc.

  4. explicit resource_adaptor_imp(const Allocator & a2);

    Effects: Initializes m_alloc with a2.

  5. explicit resource_adaptor_imp(Allocator && a2);

    Effects: Initializes m_alloc with a2.

  6. resource_adaptor_imp & operator=(const resource_adaptor_imp & other);

    Effects: Copy assigns m_alloc.

  7. resource_adaptor_imp & operator=(resource_adaptor_imp && other);

    Effects: Move assigns m_alloc.

resource_adaptor_imp public member functions

  1. allocator_type & get_allocator();
    Effects: Returns m_alloc.
  2. const allocator_type & get_allocator() const;
    Effects: Returns m_alloc.

resource_adaptor_imp protected member functions

  1. virtual void * do_allocate(std::size_t bytes, std::size_t alignment);

    Returns: Allocated memory obtained by calling m_alloc.allocate. The size and alignment of the allocated memory shall meet the requirements for a class derived from memory_resource.

  2. virtual void do_deallocate(void * p, std::size_t bytes, std::size_t alignment);

    Requires: p was previously allocated using A.allocate, where A == m_alloc, and not subsequently deallocated.

    Effects: Returns memory to the allocator using m_alloc.deallocate().

  3. virtual bool do_is_equal(const memory_resource & other) const noexcept;

    Let p be dynamic_cast<const resource_adaptor_imp*>(&other).

    Returns: false if p is null, otherwise the value of m_alloc == p->m_alloc.

resource_adaptor_imp private member functions

  1. void * priv_aligned_alloc(std::size_t bytes, std::size_t alignment);
  2. void priv_aligned_dealloc(void * aligned_ptr, std::size_t bytes, 
                              std::size_t alignment);

resource_adaptor_imp private static functions

  1. static void * priv_bookeeping_addr_from_aligned_ptr(void * aligned_ptr);
  2. static std::size_t priv_extra_bytes_for_overalignment(std::size_t alignment);
  3. static std::size_t priv_guaranteed_allocator_alignment();