[#bsl-allocator-0df] = xref:bsl.adoc[bsl]::allocator :relfileprefix: ../ :mrdocs: An STL‐compatible allocator that forwards to a `bslma::Allocator`. == Synopsis Declared in `<bslma_bslallocator.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class TYPE = polymorphic_allocator<>::value_type> class allocator : public xref:bsl/polymorphic_allocator.adoc[polymorphic_allocator<TYPE>] ---- == Description 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. == Base Classes [cols="1,4"] |=== | Name| Description | `xref:bsl/polymorphic_allocator.adoc[polymorphic_allocator<TYPE>]` | Alias for `std::pmr::polymorphic_allocator` in the `bsl` namespace. |=== == Types [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-0df/rebind.adoc[`rebind`] | Rebind this allocator to another type. |=== == Type Aliases [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-0df/const_pointer.adoc[`const_pointer`] | This `typedef` is an alias to `BaseTraits::const_pointer`. | xref:bsl/allocator-0df/const_reference.adoc[`const_reference`] | This `typedef` is an alias to a constant `value_type` reference. | xref:bsl/allocator-0df/const_void_pointer.adoc[`const_void_pointer`] | This `typedef` is an alias to `BaseTraits::const_void_pointer`. | xref:bsl/allocator-0df/difference_type.adoc[`difference_type`] | Difference type for allocations from this allocator. | xref:bsl/allocator-0df/pointer.adoc[`pointer`] | This `typedef` is an alias to `BaseTraits::pointer`. | xref:bsl/allocator-0df/reference.adoc[`reference`] | This `typedef` is an alias to a modifiable `value_type` reference. | xref:bsl/allocator-0df/size_type.adoc[`size_type`] | Size type for allocations from this allocator. | xref:bsl/allocator-0df/value_type.adoc[`value_type`] | This `typedef` is an alias to the (template parameter) `TYPE`. | xref:bsl/allocator-0df/void_pointer.adoc[`void_pointer`] | This `typedef` is an alias to `BaseTraits::void_pointer`. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-0df/2constructor-0f.adoc[`allocator`] [.small]#[constructor]# | Create an allocator that uses the default allocator mechanism. | xref:bsl/allocator-0df/2constructor-0c.adoc[`allocator`] [.small]#[constructor]# | Create an allocator that copies `original`. | xref:bsl/allocator-0df/2constructor-0bc.adoc[`allocator`] [.small]#[constructor]# | Create an allocator sharing the mechanism of the specified `original`. | xref:bsl/allocator-0df/2constructor-0b9.adoc[`allocator`] [.small]#[constructor]# | Convert a `bslma::Allocator` pointer to an `allocator` object. | xref:bsl/allocator-0df/operator_assign.adoc[`operator=`] | Assign this allocator from the specified `rhs` if it is a no‐op assignment. | xref:bsl/allocator-0df/address-08.adoc[`address`] | Return the address of the specified object `x`. | xref:bsl/allocator-0df/address-04.adoc[`address`] | Return the address of the specified object `x`. | xref:bsl/allocator-0df/allocate.adoc[`allocate`] | Return storage for `n` objects of `value_type`. | xref:bsl/allocator-0df/construct-00.adoc[`construct`] | Default‐construct an `ELEMENT_TYPE` object at the specified `address`. | xref:bsl/allocator-0df/construct-08.adoc[`construct`] | Construct an `ELEMENT_TYPE` at `address` from the arguments. | xref:bsl/allocator-0df/construct-0e.adoc[`construct`] | Construct an `ELEMENT_TYPE` at `address` using perfect forwarding. | xref:bsl/allocator-0df/deallocate.adoc[`deallocate`] | Deallocate the memory block at the specified `p` address. | xref:bsl/allocator-0df/destroy.adoc[`destroy`] | Call the destructor for the object at the specified `address`. | xref:bsl/allocator-0df/max_size.adoc[`max_size`] | Return the maximum number of elements allocatable by this allocator. | xref:bsl/allocator-0df/mechanism.adoc[`mechanism`] | Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls. | xref:bsl/allocator-0df/select_on_container_copy_construction.adoc[`select_on_container_copy_construction`] | Return a default‐constructed allocator. | xref:bsl/allocator-0df/2conversion-0e.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<allocator, IsBitwiseCopyable>`] | Return a tag declaring that this allocator is bitwise copyable. | xref:bsl/allocator-0df/2conversion-04.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<allocator, IsBitwiseEqualityComparable>`] | Declare that `allocator` is bitwise equality comparable. |=== == Specializations [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-0a.adoc[`allocator<void>`] | Specialization of `allocator` for `void`. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/format-0cb.adoc[`format`] | Format `args` according to `fmtStr` using `alloc` and locale `loc`. | xref:bsl/format-0ce.adoc[`format`] | Format `args` according to `fmtStr` using allocator `alloc`. | xref:bsl/format-0d.adoc[`format`] | Format `args` according to `fmtStr` using `alloc` and locale `loc`. | xref:bsl/format-0e.adoc[`format`] | Format `args` according to `fmtStr` using allocator `alloc`. | xref:bsl/vformat-00b.adoc[`vformat`] | Format `args` according to `fmtStr` using allocator and locale. | xref:bsl/vformat-0c3.adoc[`vformat`] | Format `args` according to `fmtStr` using the given allocator. | xref:bsl/vformat-0eb.adoc[`vformat`] | Format `args` according to `fmtStr` using the given allocator. | xref:bsl/vformat-0ef.adoc[`vformat`] | Format `args` according to `fmtStr` using allocator and locale. | xref:BloombergLP/bslfmt/format-06.adoc[`::BloombergLP::bslfmt::format`] | Format `args` according to `fmtStr` using allocator `alloc`. | xref:BloombergLP/bslfmt/format-099.adoc[`::BloombergLP::bslfmt::format`] | Format `args` according to `fmtStr` using allocator `alloc`. | xref:BloombergLP/bslfmt/vformat-0c.adoc[`::BloombergLP::bslfmt::vformat`] | Format `args` according to `fmtStr` using the given allocator. | xref:BloombergLP/bslfmt/vformat-0f.adoc[`::BloombergLP::bslfmt::vformat`] | Format `args` according to `fmtStr` using the given allocator. |=== == Derived Classes [cols="1,4"] |=== | Name| Description | xref:bsl/allocator-0a.adoc[`allocator<void>`] | Specialization of `allocator` for `void`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#