[#bsl-allocator-0c3]
= xref:bsl.adoc[bsl]::xref:bsl/allocator-0df.adoc[allocator]&lt;xref:BloombergLP/balm/MetricSampleGroup.adoc[MetricSampleGroup]&gt;
:relfileprefix: ../
:mrdocs:

An STL&hyphen;compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from `bslma&colon;&colon;Allocator`&period; This class template adheres to the allocator requirements defined in section &lsqb;allocator&period;requirements&rsqb;and implements a superset of the `std&colon;&colon;pmr&colon;&colon;polymorphic&lowbar;allocator` class template described in section &lsqb;mem&period;poly&period;allocator&period;class&rsqb;of the C&plus;&plus; standard and may be used to instantiate any &lsqb;container&rsqb;class template that follows the STL allocator protocol&period; The allocation mechanism is chosen at run&hyphen;time, giving the programmer run&hyphen;time control over how a container allocates and frees memory&period;

== Synopsis

Declared in `&lt;bslma&lowbar;bslallocator&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;&gt;
class xref:bsl/allocator-0df.adoc[allocator]&lt;xref:BloombergLP/balm/MetricSampleGroup.adoc[MetricSampleGroup]&gt;
    : public xref:bsl/polymorphic_allocator.adoc[polymorphic&lowbar;allocator&lt;MetricSampleGroup&gt;]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:bsl/polymorphic_allocator.adoc[polymorphic&lowbar;allocator&lt;MetricSampleGroup&gt;]`
| Alias for `std&colon;&colon;pmr&colon;&colon;polymorphic&lowbar;allocator` in the `bsl` namespace&period;
|===

== Types

[cols="1,4"]
|===
| Name| Description
| xref:bsl/allocator-0c3/rebind.adoc[`rebind`] 
| This nested `struct` template, parameterized by `ANY&lowbar;TYPE`, provides a namespace for an `other` type alias, which is this template instantiated with `ANY&lowbar;TYPE` instead of `TYPE`&period; Note that this allocator type is convertible to and from `other` for any type, including `void`&period;
|===


== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/allocator-0c3/const_pointer.adoc[`const&lowbar;pointer`] 
| This `typedef` is an alias to `BaseTraits&colon;&colon;const&lowbar;pointer`&period;
| xref:bsl/allocator-0c3/const_reference.adoc[`const&lowbar;reference`] 
| This `typedef` is an alias to a constant `value&lowbar;type` reference&period;
| xref:bsl/allocator-0c3/const_void_pointer.adoc[`const&lowbar;void&lowbar;pointer`] 
| This `typedef` is an alias to `BaseTraits&colon;&colon;const&lowbar;void&lowbar;pointer`&period;
| xref:bsl/allocator-0c3/difference_type.adoc[`difference&lowbar;type`] 
| Difference type for allocations from this allocator&period;
| xref:bsl/allocator-0c3/pointer.adoc[`pointer`] 
| This `typedef` is an alias to `BaseTraits&colon;&colon;pointer`&period;
| xref:bsl/allocator-0c3/reference.adoc[`reference`] 
| This `typedef` is an alias to a modifiable `value&lowbar;type` reference&period;
| xref:bsl/allocator-0c3/size_type.adoc[`size&lowbar;type`] 
| Size type for allocations from this allocator&period;
| xref:bsl/allocator-0c3/value_type.adoc[`value&lowbar;type`] 
| This `typedef` is an alias to the (template parameter) `TYPE`&period;
| xref:bsl/allocator-0c3/void_pointer.adoc[`void&lowbar;pointer`] 
| This `typedef` is an alias to `BaseTraits&colon;&colon;void&lowbar;pointer`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/allocator-0c3/2constructor-06e.adoc[`allocator`]         [.small]#[constructor]#
| Create an allocator that will forward allocation calls to the object pointed to by `bslma&colon;&colon;Default&colon;&colon;defaultAllocator()`&period; Postcondition&colon; &grave; this&hyphen;&gt;mechanism() &equals;&equals; bslma&colon;&colon;Default&colon;&colon;defaultAllocator() &grave;
| xref:bsl/allocator-0c3/2constructor-06c.adoc[`allocator`]         [.small]#[constructor]#
| Create a copy of this allocator&period;
| xref:bsl/allocator-0c3/2constructor-0e.adoc[`allocator`]         [.small]#[constructor]#
| Convert a `bslma&colon;&colon;Allocator` pointer to an `allocator` object that forwards allocation calls to the object pointed to by the specified `mechanism`&period; If `mechanism` is 0, then the currently installed default allocator is used instead&period; Postcondition&colon; &grave; this&hyphen;&gt;mechanism() &equals;&equals; bslma&colon;&colon;Default&colon;&colon;allocator(mechanism) &grave;
| xref:bsl/allocator-0c3/2constructor-01.adoc[`allocator`]         [.small]#[constructor]#
| Create an allocator sharing the same mechanism object as the specified `original`&period; The newly constructed allocator will compare equal to `original`, even though they may be instantiated on different types&period; Postconditions&colon; &grave; &ast;this &equals;&equals; original this&hyphen;&gt;mechanism() &equals;&equals; original&period;mechanism() &grave;
| xref:bsl/allocator-0c3/operator_assign-0d.adoc[`operator&equals;`] 
| Modify this allocator to use the same mechanism as the specified `rhs` allocator and return a modifiable reference to this object&period; Note that `bsl&colon;&colon;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&semi; ideally, such code would be replaced by more sophisticated metaprogramming that avoided calls to this operator entirely&period; Invoking this assignment will result in a review error unless `rhs &equals;&equals; &ast;this`, i&period;e&period;, when the assignment would be a no&hyphen;op&period; In the future, the review error may be replaced with an a hard assertion failure&period;
| xref:bsl/allocator-0c3/operator_assign-06.adoc[`operator&equals;`]  [.small]#[deleted]#
| 
| xref:bsl/allocator-0c3/address-06.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&amp;`&period;
| xref:bsl/allocator-0c3/address-01.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&amp;`&period;
| xref:bsl/allocator-0c3/allocate-06.adoc[`allocate`] 
| 
| xref:bsl/allocator-0c3/allocate-0a.adoc[`allocate`] 
| 
| xref:bsl/allocator-0c3/allocate_bytes.adoc[`allocate&lowbar;bytes`] 
| 
| xref:bsl/allocator-0c3/allocate_object.adoc[`allocate&lowbar;object`] 
| 
| xref:bsl/allocator-0c3/construct-03.adoc[`construct`] 
| Create a default&hyphen;constructed object of (template parameter) `ELEMENT&lowbar;TYPE` at the specified `address`&period; If `ELEMENT&lowbar;TYPE` supports `bslma`&hyphen;style allocation, this allocator passes itself to the extended default constructor&period; If the constructor throws, the memory at `address` is left in an unspecified state&period; The behavior is undefined unless `address` refers to a block of sufficient size and properly aligned for objects of `ELEMENT&lowbar;TYPE`&period;
| xref:bsl/allocator-0c3/construct-05.adoc[`construct`] 
| 
| xref:bsl/allocator-0c3/construct-0c.adoc[`construct`] 
| Create an object of (template parameter) `ELEMENT&lowbar;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&lowbar;TYPE`&period; If `ELEMENT&lowbar;TYPE` supports `bslma`&hyphen;style allocation, this allocator passes itself to the constructor&period; If the constructor throws, the memory at `address` is left in an unspecified state&period; Note that, in C&plus;&plus;03, perfect forwarding is limited such that any lvalue reference in the `arguments` parameter pack is const&hyphen;qualified when forwarded to the `ELEMENT&lowbar;TYPE` constructor&semi; only `argument1` can be forwarded as an unqualified lvalue&period; The behavior is undefined unless `address` refers to a block of sufficient size and properly aligned for objects of `ELEMENT&lowbar;TYPE`&period;
| xref:bsl/allocator-0c3/construct-08.adoc[`construct`] 
| Same as the preceding `construct` overload, using perfect forwarding&period;
| xref:bsl/allocator-0c3/deallocate-0c.adoc[`deallocate`] 
| 
| xref:bsl/allocator-0c3/deallocate-0f.adoc[`deallocate`] 
| Deallocate a block of memory at the specified `p` address by returning it to the memory resource held by this allocator&period; Optionally specify the number of objects, `n`, to deallocate&period; 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&lowbar;type` and not yet deallocated&period;
| xref:bsl/allocator-0c3/deallocate_bytes.adoc[`deallocate&lowbar;bytes`] 
| 
| xref:bsl/allocator-0c3/deallocate_object.adoc[`deallocate&lowbar;object`] 
| 
| xref:bsl/allocator-0c3/delete_object.adoc[`delete&lowbar;object`] 
| 
| xref:bsl/allocator-0c3/destroy-0c.adoc[`destroy`] 
| Call the `TYPE` destructor for the object pointed to by the specified `address`&period; Do not directly deallocate any memory&period;
| xref:bsl/allocator-0c3/destroy-03.adoc[`destroy`] 
| 
| xref:bsl/allocator-0c3/max_size.adoc[`max&lowbar;size`] 
| 
| xref:bsl/allocator-0c3/mechanism.adoc[`mechanism`] 
| Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls&period;
| xref:bsl/allocator-0c3/new_object.adoc[`new&lowbar;object`] 
| 
| xref:bsl/allocator-0c3/resource.adoc[`resource`] 
| 
| xref:bsl/allocator-0c3/select_on_container_copy_construction.adoc[`select&lowbar;on&lowbar;container&lowbar;copy&lowbar;construction`] 
| Return a default&hyphen;constructed allocator&period;
| xref:bsl/allocator-0c3/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;allocator&lt;MetricSampleGroup&gt;, IsBitwiseEqualityComparable&gt;`] 
| 
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
