BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsl::polymorphic_allocator< TYPE > Class Template Reference

#include <bslma_polymorphicallocator.h>

Inheritance diagram for bsl::polymorphic_allocator< TYPE >:
bsl::allocator< BloombergLP::bslma::BslAllocator_Voidish > bsl::allocator< ELEMENT_TYPE > bsl::allocator< char > bsl::allocator< OBJECT_TYPE > bsl::allocator< int > bsl::allocator< VALUE > bsl::allocator< TYPE > bsl::allocator< void > bsl::allocator_traits< allocator< TYPE > >::rebind_alloc< ELEMENT_TYPE >

Classes

struct  rebind
 

Public Types

typedef std::size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef TYPE * pointer
 
typedef const TYPE * const_pointer
 
typedef TYPE & reference
 
typedef const TYPE & const_reference
 
typedef TYPE value_type
 

Public Member Functions

 polymorphic_allocator () BSLS_KEYWORD_NOEXCEPT
 
 polymorphic_allocator (memory_resource *r)
 
 polymorphic_allocator (const polymorphic_allocator &original) BSLS_KEYWORD_NOEXCEPT
 
template<class ANY_TYPE >
 polymorphic_allocator (const polymorphic_allocator< ANY_TYPE > &original) BSLS_KEYWORD_NOEXCEPT
 
 ~polymorphic_allocator ()=default
 
BSLS_ANNOTATION_NODISCARD TYPE * allocate (std::size_t n)
 
void deallocate (TYPE *p, std::size_t n)
 
template<class ELEMENT_TYPE >
void construct (ELEMENT_TYPE *address)
 
template<class ELEMENT_TYPE , class ARG1 , class... ARGS>
void construct (ELEMENT_TYPE *address, ARG1 &argument1, ARGS &&... arguments)
 
template<class ELEMENT_TYPE , class ARG1 , class... ARGS>
void construct (ELEMENT_TYPE *address, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
 
template<class ELEMENT_TYPE >
void destroy (ELEMENT_TYPE *address)
 
pointer address (reference x) const
 
const_pointer address (const_reference x) const
 
BSLS_KEYWORD_CONSTEXPR size_type max_size () const
 
memory_resourceresource () const
 Return the address of the memory resource supplied on construction.
 
polymorphic_allocator select_on_container_copy_construction () const
 Return a default-constructed polymorphic_allocator.
 

Friends

bool operator== (const polymorphic_allocator &a, const polymorphic_allocator &b) BSLS_KEYWORD_NOEXCEPT
 
bool operator!= (const polymorphic_allocator &a, const polymorphic_allocator &b) BSLS_KEYWORD_NOEXCEPT
 

Detailed Description

template<class TYPE = unsigned char>
class bsl::polymorphic_allocator< TYPE >

An STL-compatible proxy for any resource class derived from bsl::memory_resource. This class template is a pre-C++17 implementation of std::pmr::polymorphic_allocator from the C++17 Standard Library. Note that there are a number of methods (e.g., max_size ) that are not in the C++17 version of this class. These members exist for compatibility with C++03 versions of the standard library, which don't use allocator_traits.

See bslma_polymorphicallocator

Member Typedef Documentation

◆ const_pointer

template<class TYPE = unsigned char>
typedef const TYPE* bsl::polymorphic_allocator< TYPE >::const_pointer

◆ const_reference

template<class TYPE = unsigned char>
typedef const TYPE& bsl::polymorphic_allocator< TYPE >::const_reference

◆ difference_type

template<class TYPE = unsigned char>
typedef std::ptrdiff_t bsl::polymorphic_allocator< TYPE >::difference_type

◆ pointer

template<class TYPE = unsigned char>
typedef TYPE* bsl::polymorphic_allocator< TYPE >::pointer

◆ reference

template<class TYPE = unsigned char>
typedef TYPE& bsl::polymorphic_allocator< TYPE >::reference

◆ size_type

template<class TYPE = unsigned char>
typedef std::size_t bsl::polymorphic_allocator< TYPE >::size_type

◆ value_type

template<class TYPE = unsigned char>
typedef TYPE bsl::polymorphic_allocator< TYPE >::value_type

Constructor & Destructor Documentation

◆ polymorphic_allocator() [1/4]

template<class TYPE >
bsl::polymorphic_allocator< TYPE >::polymorphic_allocator ( )

Create an allocator that will forward allocation calls to the object pointed to by bslma::Default::defaultAllocator(). Postcondition:

memory_resource * resource() const
Return the address of the memory resource supplied on construction.
Definition bslma_polymorphicallocator.h:1048
static Allocator * defaultAllocator()
Definition bslma_default.h:889

Note that in this C++03 implementation, the default memory resource is the same as bslma::Default::defaultAllocator().

◆ polymorphic_allocator() [2/4]

template<class TYPE >
bsl::polymorphic_allocator< TYPE >::polymorphic_allocator ( memory_resource r)
inline

Convert a memory_resource pointer to a polymorphic_allocator object that forwards allocation calls to the object pointed to by the specified r. Postcondition:

this->resource() == r

The behavior is undefined if r is null.

◆ polymorphic_allocator() [3/4]

template<class TYPE >
bsl::polymorphic_allocator< TYPE >::polymorphic_allocator ( const polymorphic_allocator< TYPE > &  original)
inline

Create an allocator sharing the same resource object as the specified original. The newly constructed allocator will compare equal to original, even though they may be instantiated on different types. Postconditions:

*this == original
this->resource() == original.resource();

◆ polymorphic_allocator() [4/4]

template<class TYPE >
template<class ANY_TYPE >
bsl::polymorphic_allocator< TYPE >::polymorphic_allocator ( const polymorphic_allocator< ANY_TYPE > &  original)
inline

◆ ~polymorphic_allocator()

template<class TYPE = unsigned char>
bsl::polymorphic_allocator< TYPE >::~polymorphic_allocator ( )
default

Destroy this object. Note that this does not delete the object pointed to by 'resource()'.

Member Function Documentation

◆ address() [1/2]

template<class TYPE >
polymorphic_allocator< TYPE >::const_pointer bsl::polymorphic_allocator< TYPE >::address ( const_reference  x) const
inline

◆ address() [2/2]

template<class TYPE >
polymorphic_allocator< TYPE >::pointer bsl::polymorphic_allocator< TYPE >::address ( reference  x) const
inline

Return the address of the object referred to by the specified x reference, even if the (template parameter) TYPE overloads the unary operator&.

◆ allocate()

template<class TYPE >
TYPE * bsl::polymorphic_allocator< TYPE >::allocate ( std::size_t  n)
inline

Return a block of memory having sufficient size and alignment to hold the specified n objects of value_type, allocated from the memory resource held by this allocator.

◆ construct() [1/3]

template<class TYPE >
template<class ELEMENT_TYPE >
void bsl::polymorphic_allocator< TYPE >::construct ( ELEMENT_TYPE *  address)
inline

Create a default-constructed object of (template parameter) ELEMENT_TYPE at the specified address. If ELEMENT_TYPE supports bslma-style allocation, this allocator passes itself to the extended default constructor. If the constructor throws, the memory at address is left in an unspecified state. The behavior is undefined unless address refers to a block of memory having sufficient size and alignment for an object of ELEMENT_TYPE.

◆ construct() [2/3]

template<class TYPE >
template<class ELEMENT_TYPE , class ARG1 , class... ARGS>
void bsl::polymorphic_allocator< TYPE >::construct ( ELEMENT_TYPE *  address,
ARG1 &  argument1,
ARGS &&...  arguments 
)
inline

Create an object of (template parameter) ELEMENT_TYPE at the specified address, constructed by forwarding the specified argument1 and the (variable number of) additional specified arguments to the corresponding constructor of ELEMENT_TYPE. If ELEMENT_TYPE supports bslma-style allocation, this allocator passes itself to the constructor. If the constructor throws, the memory at address is left in an unspecified state. Note that, in C++03, perfect forwarding is limited such that any lvalue reference in the arguments parameter pack is const-qualified when forwarded to the ELEMENT_TYPE constructor; only argument1 can be forwarded as an unqualified lvalue. The behavior is undefined unless address refers to a block of memory having sufficient size and alignment for an object of ELEMENT_TYPE.

◆ construct() [3/3]

template<class TYPE >
template<class ELEMENT_TYPE , class ARG1 , class... ARGS>
void bsl::polymorphic_allocator< TYPE >::construct ( ELEMENT_TYPE *  address,
BSLS_COMPILERFEATURES_FORWARD_REF(ARG1)  argument1,
ARGS &&...  arguments 
)
inline

◆ deallocate()

template<class TYPE >
void bsl::polymorphic_allocator< TYPE >::deallocate ( TYPE *  p,
std::size_t  n 
)
inline

Deallocate a block of memory having sufficient size and alignment to hold the specified n objects of value_type by returning it to the memory resource held by this allocator. The behavior is undefined unless p is the address of a block previously allocated by a call to allocate with the same n and not yet deallocated.

◆ destroy()

template<class TYPE >
template<class ELEMENT_TYPE >
void bsl::polymorphic_allocator< TYPE >::destroy ( ELEMENT_TYPE *  address)
inline

Call the ELEMENT_TYPE destructor for the object at the specified address but do not deallocate the memory at address.

◆ max_size()

template<class TYPE >
BSLS_KEYWORD_CONSTEXPR polymorphic_allocator< TYPE >::size_type bsl::polymorphic_allocator< TYPE >::max_size ( ) const
inline

Return the maximum number of elements of (template parameter) TYPE that can be allocated using this allocator. Note that there is no guarantee that attempts at allocating fewer elements than the value returned by max_size will not throw.

◆ resource()

template<class TYPE >
memory_resource * bsl::polymorphic_allocator< TYPE >::resource ( ) const
inline

◆ select_on_container_copy_construction()

template<class TYPE >
polymorphic_allocator< TYPE > bsl::polymorphic_allocator< TYPE >::select_on_container_copy_construction ( ) const
inline

Friends And Related Symbol Documentation

◆ operator!=

template<class TYPE = unsigned char>
bool operator!= ( const polymorphic_allocator< TYPE > &  a,
const polymorphic_allocator< TYPE > &  b 
)
friend

Return true if memory allocated from either of the specified a or b allocators cannot necessarily be deallocated from the other; otherwise return false. This operator is selected by overload resolution if at least one argument is a specialization of polymorphic_allocator and the other is either the same specialization or is convertible to polymorphic_allocator. Note that this operator is a "hidden friend" so that it is found by only by ADL and is not considered during overload resoution if neither argument is a specialization of polymorphic_allocator; see https://cplusplus.github.io/LWG/issue3683.

◆ operator==

template<class TYPE = unsigned char>
bool operator== ( const polymorphic_allocator< TYPE > &  a,
const polymorphic_allocator< TYPE > &  b 
)
friend

Return true if memory allocated from either of the specified a or b allocators can be deallocated from the other; otherwise return false. This operator is selected by overload resolution if at least one argument is a specialization of polymorphic_allocator and the other is either the same specialization or is convertible to polymorphic_allocator. Note that this operator is a "hidden friend" so that it is found by only by ADL and is not considered during overload resoution if neither argument is a specialization of polymorphic_allocator; see https://cplusplus.github.io/LWG/issue3683.


The documentation for this class was generated from the following file: