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

#include <bslma_bslallocator.h>

Inheritance diagram for bsl::allocator< TYPE >:
bsl::polymorphic_allocator< TYPE >

Classes

struct  rebind
 

Public Types

typedef TYPE value_type
 
typedef value_typereference
 
typedef value_type const & const_reference
 
typedef BaseTraits::size_type size_type
 
typedef BaseTraits::difference_type difference_type
 
typedef BaseTraits::pointer pointer
 
typedef BaseTraits::const_pointer const_pointer
 
typedef BaseTraits::void_pointer void_pointer
 
typedef BaseTraits::const_void_pointer const_void_pointer
 
- Public Types inherited from bsl::polymorphic_allocator< TYPE >
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

 BSLMF_NESTED_TRAIT_DECLARATION (allocator, BloombergLP::bslmf::IsBitwiseCopyable)
 
 BSLMF_NESTED_TRAIT_DECLARATION (allocator, BloombergLP::bslmf::IsBitwiseEqualityComparable)
 
 allocator ()
 
 allocator (BloombergLP::bslma::Allocator *mechanism)
 
 allocator (const allocator &original) BSLS_KEYWORD_NOEXCEPT
 
template<class ANY_TYPE >
 allocator (const allocator< ANY_TYPE > &original) BSLS_KEYWORD_NOEXCEPT
 
 ~allocator ()=default
 
BSLMA_BSLALLOCATOR_DEPRECATE_ASSIGN allocatoroperator= (const allocator &rhs)
 
BSLS_ANNOTATION_NODISCARD pointer allocate (size_type n, const void *hint=0)
 
void deallocate (TYPE *p, std::size_t n=1)
 
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
 
BloombergLP::bslma::Allocator * mechanism () const
 
allocator select_on_container_copy_construction () const
 Return a default-constructed allocator.
 
- Public Member Functions inherited from bsl::polymorphic_allocator< TYPE >
 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.
 

Detailed Description

template<class TYPE = polymorphic_allocator<>::value_type>
class bsl::allocator< TYPE >

An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements] and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class] of the C++ standard and may be used to instantiate any [container] class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.

See bslma_bslallocator

Member Typedef Documentation

◆ const_pointer

template<class TYPE = polymorphic_allocator<>::value_type>
typedef BaseTraits::const_pointer bsl::allocator< TYPE >::const_pointer

◆ const_reference

template<class TYPE = polymorphic_allocator<>::value_type>
typedef value_type const& bsl::allocator< TYPE >::const_reference

◆ const_void_pointer

template<class TYPE = polymorphic_allocator<>::value_type>
typedef BaseTraits::const_void_pointer bsl::allocator< TYPE >::const_void_pointer

◆ difference_type

template<class TYPE = polymorphic_allocator<>::value_type>
typedef BaseTraits::difference_type bsl::allocator< TYPE >::difference_type

◆ pointer

template<class TYPE = polymorphic_allocator<>::value_type>
typedef BaseTraits::pointer bsl::allocator< TYPE >::pointer

◆ reference

template<class TYPE = polymorphic_allocator<>::value_type>
typedef value_type& bsl::allocator< TYPE >::reference

◆ size_type

template<class TYPE = polymorphic_allocator<>::value_type>
typedef BaseTraits::size_type bsl::allocator< TYPE >::size_type

◆ value_type

template<class TYPE = polymorphic_allocator<>::value_type>
typedef TYPE bsl::allocator< TYPE >::value_type

◆ void_pointer

template<class TYPE = polymorphic_allocator<>::value_type>
typedef BaseTraits::void_pointer bsl::allocator< TYPE >::void_pointer

Constructor & Destructor Documentation

◆ allocator() [1/4]

template<class TYPE >
bsl::allocator< TYPE >::allocator ( )
inline

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

BloombergLP::bslma::Allocator * mechanism() const
Definition bslma_bslallocator.h:1126
static Allocator * defaultAllocator()
Definition bslma_default.h:889

◆ allocator() [2/4]

template<class TYPE >
bsl::allocator< TYPE >::allocator ( BloombergLP::bslma::Allocator *  mechanism)
inline

Convert a bslma::Allocator pointer to an allocator object that forwards allocation calls to the object pointed to by the specified mechanism. If mechanism is 0, then the currently installed default allocator is used instead. Postcondition:

static Allocator * allocator(Allocator *basicAllocator=0)
Definition bslma_default.h:897

◆ allocator() [3/4]

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

◆ allocator() [4/4]

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

Create an allocator sharing the same mechanism 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->mechanism() == original.mechanism()

◆ ~allocator()

template<class TYPE = polymorphic_allocator<>::value_type>
bsl::allocator< TYPE >::~allocator ( )
default

Member Function Documentation

◆ address() [1/2]

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

◆ address() [2/2]

template<class TYPE >
allocator< TYPE >::pointer bsl::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 >
allocator< TYPE >::pointer bsl::allocator< TYPE >::allocate ( size_type  n,
const void *  hint = 0 
)
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. Optionally specify a hint, which is ignored by this allocator type but theoretically used by other allocators as an aid for optimizing locality.

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/2]

template<class TYPE = polymorphic_allocator<>::value_type>
bsl::allocator< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( allocator< TYPE >  ,
BloombergLP::bslmf::IsBitwiseCopyable   
)

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/2]

template<class TYPE = polymorphic_allocator<>::value_type>
bsl::allocator< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( allocator< TYPE >  ,
BloombergLP::bslmf::IsBitwiseEqualityComparable   
)

◆ construct() [1/3]

template<class TYPE >
template<class ELEMENT_TYPE >
void bsl::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 sufficient size and properly aligned for objects of ELEMENT_TYPE.

◆ construct() [2/3]

template<class TYPE >
template<class ELEMENT_TYPE , class ARG1 , class... ARGS>
void bsl::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 sufficient size and properly aligned for objects of ELEMENT_TYPE.

◆ construct() [3/3]

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

◆ deallocate()

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

Deallocate a block of memory at the specified p address by returning it to the memory resource held by this allocator. Optionally specify the number of objects, n, to deallocate. The behavior is undefined unless p is the address of a block previously allocated by a call to allocate with the same n from a copy of this allocator having the same value_type and not yet deallocated.

◆ destroy()

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

Call the TYPE destructor for the object pointed to by the specified address. Do not directly deallocate any memory.

◆ max_size()

template<class TYPE >
BSLS_KEYWORD_CONSTEXPR allocator< TYPE >::size_type bsl::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.

◆ mechanism()

template<class TYPE >
BloombergLP::bslma::Allocator * bsl::allocator< TYPE >::mechanism ( ) const
inline

Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls.

◆ operator=()

template<class TYPE >
allocator< TYPE > & bsl::allocator< TYPE >::operator= ( const allocator< TYPE > &  rhs)
inline

DEPRECATED bsl::allocator should not be assigned. Modify this allocator to use the same mechanism as the specified rhs allocator and return a modifiable reference to this object. Note that bsl::allocator objects should never be assigned at runtime, but, in the absence of if constexpr, such assignments can sometimes be found legitimately in dead branches (branches that are never taken at runtime) within function templates; ideally, such code would be replaced by more sophisticated metaprogramming that avoided calls to this operator entirely. Invoking this assignment will result in a review error unless rhs == *this, i.e., when the assignment would be a no-op. In the future, the review error may be replaced with an a hard assertion failure.

◆ select_on_container_copy_construction()

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

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