cpp/named req/Allocator

Encapsulates strategies for access/addressing, allocation/deallocation and construction/destruction of objects.

Every standard library component that may need to allocate or release storage, from std, std, and every container except std, to std, does so through an : an object of a class type that satisfies the following requirements.

The implementation of many allocator requirements is optional because all allocator-aware classes, including standard library containers, access allocators indirectly through std, and std supplies the default implementation of those requirements.

Requirements
Given
 * , a
 * , an type for type
 * , an object of type
 * , the corresponding type for some cv-unqualified object type  (as obtained by rebinding )
 * , an object of type
 * , a value of type, obtained by calling
 * , a value of type, obtained by conversion from
 * , a value of type, obtained by conversion from
 * , a value of type, obtained by conversion from or from
 * , a dereferenceable pointer to some cv-unqualified object type
 * , an lvalue of type obtained by the expression
 * , a value of type

Notes:

Given
 * and, objects of (possibly different) types , , , or


 * Then, and  are equivalently-valued pointer values, if and only if both  and  can be explicitly converted to the two corresponding objects  and  of type, using a sequence of s using only these four types, and the expression  evaluates to.

Given
 * and, objects of type


 * Then, for the expression and  either or both objects may be replaced by an equivalently-valued object of type  with no change in semantics.

Given
 * and, objects of type


 * Then, for the expressions, , , , , , either or both objects may be replaced by an equivalently-valued object of type  with no change in semantics.

The above requirements make it possible to compare 's s and s.

{{rrev|since=c++17|

Allocator completeness requirements
An allocator type for type  additionally satisfies the allocator completeness requirements if both of the following are true regardless of whether  is a complete type: }}
 * is a complete type
 * Except for, all the member types of are complete types.

Stateful and stateless allocators
Every type is either stateful or stateless. Generally, a stateful allocator type can have unequal values which denote distinct memory resources, while a stateless allocator type denotes a single memory resource.

Instances of a stateless allocator type always compare equal. Stateless allocator types are typically implemented as empty classes and suitable for empty base class optimization.

Fancy pointers
When the member type is not a raw pointer type, it is commonly referred to as a. Such pointers were introduced to support segmented memory architectures and are used today to access objects allocated in address spaces that differ from the homogeneous virtual address space that is accessed by raw pointers. An example of a fancy pointer is the mapping address-independent pointer, which makes it possible to allocate node-based data structures such as std in shared memory and memory mapped files mapped in different addresses in every process. Fancy pointers can be used independently of the allocator that provided them.

Standard library
The following standard library components satisfy the requirements: