[#bsl-allocator-014] = xref:bsl.adoc[bsl]::xref:bsl/allocator-0df.adoc[allocator]<unsigned long long> :relfileprefix: ../ :mrdocs: 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>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<> class xref:bsl/allocator-0df.adoc[allocator]<unsigned long long> : public xref:bsl/polymorphic_allocator.adoc[polymorphic_allocator<unsigned long long>] ---- == Base Classes [cols="1,4"] |=== | Name| Description | `xref:bsl/polymorphic_allocator.adoc[polymorphic_allocator<unsigned long long>]` | Alias for `std::pmr::polymorphic_allocator` in the `bsl` namespace. |=== == Types [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-014/rebind.adoc[`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 [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-014/const_pointer.adoc[`const_pointer`] | This `typedef` is an alias to `BaseTraits::const_pointer`. | xref:bsl/allocator-014/const_reference.adoc[`const_reference`] | This `typedef` is an alias to a constant `value_type` reference. | xref:bsl/allocator-014/const_void_pointer.adoc[`const_void_pointer`] | This `typedef` is an alias to `BaseTraits::const_void_pointer`. | xref:bsl/allocator-014/difference_type.adoc[`difference_type`] | Difference type for allocations from this allocator. | xref:bsl/allocator-014/pointer.adoc[`pointer`] | This `typedef` is an alias to `BaseTraits::pointer`. | xref:bsl/allocator-014/reference.adoc[`reference`] | This `typedef` is an alias to a modifiable `value_type` reference. | xref:bsl/allocator-014/size_type.adoc[`size_type`] | Size type for allocations from this allocator. | xref:bsl/allocator-014/value_type.adoc[`value_type`] | This `typedef` is an alias to the (template parameter) `TYPE`. | xref:bsl/allocator-014/void_pointer.adoc[`void_pointer`] | This `typedef` is an alias to `BaseTraits::void_pointer`. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-014/2constructor-0c.adoc[`allocator`] [.small]#[constructor]# | Create an allocator that will forward allocation calls to the object pointed to by `bslma::Default::defaultAllocator()`. Postcondition: ` this‐>mechanism() == bslma::Default::defaultAllocator() ` | xref:bsl/allocator-014/2constructor-0d.adoc[`allocator`] [.small]#[constructor]# | Create a copy of this allocator. | xref:bsl/allocator-014/2constructor-03.adoc[`allocator`] [.small]#[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) ` | xref:bsl/allocator-014/2constructor-00.adoc[`allocator`] [.small]#[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() ` | xref:bsl/allocator-014/operator_assign-0c.adoc[`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. | xref:bsl/allocator-014/operator_assign-02.adoc[`operator=`] [.small]#[deleted]# | | xref:bsl/allocator-014/address-0f.adoc[`address`] | Return the address of the object referred to by the specified `x` reference, even if the (template parameter) `TYPE` overloads the unary `operator&`. | xref:bsl/allocator-014/address-0d.adoc[`address`] | Return the address of the object referred to by the specified `x` reference, even if the (template parameter) `TYPE` overloads the unary `operator&`. | xref:bsl/allocator-014/allocate-06.adoc[`allocate`] | | xref:bsl/allocator-014/allocate-0b.adoc[`allocate`] | | xref:bsl/allocator-014/allocate_bytes.adoc[`allocate_bytes`] | | xref:bsl/allocator-014/allocate_object.adoc[`allocate_object`] | | xref:bsl/allocator-014/construct-08.adoc[`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`. | xref:bsl/allocator-014/construct-0dd.adoc[`construct`] | | xref:bsl/allocator-014/construct-0d4.adoc[`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`. | xref:bsl/allocator-014/construct-0e.adoc[`construct`] | Same as the preceding `construct` overload, using perfect forwarding. | xref:bsl/allocator-014/deallocate-0d.adoc[`deallocate`] | | xref:bsl/allocator-014/deallocate-02.adoc[`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. | xref:bsl/allocator-014/deallocate_bytes.adoc[`deallocate_bytes`] | | xref:bsl/allocator-014/deallocate_object.adoc[`deallocate_object`] | | xref:bsl/allocator-014/delete_object.adoc[`delete_object`] | | xref:bsl/allocator-014/destroy-01.adoc[`destroy`] | Call the `TYPE` destructor for the object pointed to by the specified `address`. Do not directly deallocate any memory. | xref:bsl/allocator-014/destroy-03.adoc[`destroy`] | | xref:bsl/allocator-014/max_size.adoc[`max_size`] | | xref:bsl/allocator-014/mechanism.adoc[`mechanism`] | Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls. | xref:bsl/allocator-014/new_object.adoc[`new_object`] | | xref:bsl/allocator-014/resource.adoc[`resource`] | | xref:bsl/allocator-014/select_on_container_copy_construction.adoc[`select_on_container_copy_construction`] | Return a default‐constructed allocator. | xref:bsl/allocator-014/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<allocator<unsigned long long>, IsBitwiseEqualityComparable>`] | |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#