BDE 4.14.0 Production release
|
#include <bslma_polymorphicallocator.h>
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_resource * | resource () 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 |
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
.
typedef const TYPE* bsl::polymorphic_allocator< TYPE >::const_pointer |
typedef const TYPE& bsl::polymorphic_allocator< TYPE >::const_reference |
typedef std::ptrdiff_t bsl::polymorphic_allocator< TYPE >::difference_type |
typedef TYPE* bsl::polymorphic_allocator< TYPE >::pointer |
typedef TYPE& bsl::polymorphic_allocator< TYPE >::reference |
typedef std::size_t bsl::polymorphic_allocator< TYPE >::size_type |
typedef TYPE bsl::polymorphic_allocator< TYPE >::value_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:
Note that in this C++03 implementation, the default memory resource is the same as bslma::Default::defaultAllocator()
.
|
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:
The behavior is undefined if r
is null.
|
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:
|
inline |
|
default |
Destroy this object. Note that this does not delete the object pointed to by 'resource()'.
|
inline |
|
inline |
Return the address of the object referred to by the specified x
reference, even if the (template parameter) TYPE
overloads the unary operator&
.
|
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.
|
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
.
|
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
.
|
inline |
|
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.
|
inline |
Call the ELEMENT_TYPE
destructor for the object at the specified address
but do not deallocate the memory at address
.
|
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.
|
inline |
|
inline |
|
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.
|
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.