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.

Synopsis

Declared in <bslma_bslallocator.h>

template<>
class allocator<unsigned int>
    : public polymorphic_allocator<unsigned int>

Base Classes

Name

Description

polymorphic_allocator<unsigned int>

Alias for std::pmr::polymorphic_allocator in the bsl namespace.

Types

Name

Description

rebind

This nested struct template, parameterized by ANY_TYPE, provides a namespace for an other type alias, which is this template instantiated with ANY_TYPE instead of TYPE. Note that this allocator type is convertible to and from other for any type, including void.

Type Aliases

Name

Description

const_pointer

This typedef is an alias to BaseTraits::const_pointer.

const_reference

This typedef is an alias to a constant value_type reference.

const_void_pointer

This typedef is an alias to BaseTraits::const_void_pointer.

difference_type

Difference type for allocations from this allocator.

pointer

This typedef is an alias to BaseTraits::pointer.

reference

This typedef is an alias to a modifiable value_type reference.

size_type

Size type for allocations from this allocator.

value_type

This typedef is an alias to the (template parameter) TYPE.

void_pointer

This typedef is an alias to BaseTraits::void_pointer.

Member Functions

Name

Description

allocator [constructor]

Create an allocator that will forward allocation calls to the object pointed to by bslma::Default::defaultAllocator(). Postcondition: ` this‐>mechanism() == bslma::Default::defaultAllocator() `

allocator [constructor]

Create a copy of this allocator.

allocator [constructor]

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: ` this‐>mechanism() == bslma::Default::allocator(mechanism) `

allocator [constructor]

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() `

operator=

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.

operator= [deleted]

address

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

address

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

allocate

allocate

allocate_bytes

allocate_object

construct

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

construct

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

Same as the preceding construct overload, using perfect forwarding.

deallocate

deallocate

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.

deallocate_bytes

deallocate_object

delete_object

destroy

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

destroy

max_size

mechanism

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

new_object

resource

select_on_container_copy_construction

Return a default‐constructed allocator.

operator BloombergLP::bslmf::NestedTraitDeclaration<allocator<unsigned int>, IsBitwiseEqualityComparable>

Created with MrDocs