Files
cppdraft_translate/cppdraft/allocator/requirements.md
2025-10-25 03:02:53 +03:00

1030 lines
33 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[allocator.requirements]
# 16 Library introduction [[library]](./#library)
## 16.4 Library-wide requirements [[requirements]](requirements#allocator.requirements)
### 16.4.4 Requirements on types and expressions [[utility.requirements]](utility.requirements#allocator.requirements)
#### 16.4.4.6 *Cpp17Allocator* requirements [allocator.requirements]
#### [16.4.4.6.1](#general) General [[allocator.requirements.general]](allocator.requirements.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2138)
The library describes a standard set of requirements for [*allocators*](#def:allocators),
which are class-type objects that encapsulate the information about an allocation model[.](#general-1.sentence-1)
This information includes the knowledge of pointer types, the type of their
difference, the type of the size of objects in this allocation model, as well
as the memory allocation and deallocation primitives for it[.](#general-1.sentence-2)
All of the
string types ([[strings]](strings "27Strings library")),
containers ([[containers]](containers "23Containers library")) (except array and inplace_vector),
string buffers and string streams ([[input.output]](input.output "31Input/output library")), and[match_results](re "28.6Regular expressions library[re]") are parameterized in terms of
allocators[.](#general-1.sentence-3)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2150)
In [allocator.requirements],
- [(2.1)](#general-2.1)
T, U, C denote
any cv-unqualified object type ([[basic.types.general]](basic.types.general#term.object.type "6.9.1General")),
- [(2.2)](#general-2.2)
X denotes an allocator class for type T,
- [(2.3)](#general-2.3)
Y denotes the corresponding allocator class for type U,
- [(2.4)](#general-2.4)
XX denotes the type allocator_traits<X>,
- [(2.5)](#general-2.5)
YY denotes the type allocator_traits<Y>,
- [(2.6)](#general-2.6)
a, a1, a2 denote lvalues of type X,
- [(2.7)](#general-2.7)
u denotes the name of a variable being declared,
- [(2.8)](#general-2.8)
b denotes a value of type Y,
- [(2.9)](#general-2.9)
c denotes a pointer of type C* through which indirection is valid,
- [(2.10)](#general-2.10)
p denotes a value of type XX::pointer obtained by calling a1.allocate, where a1 == a,
- [(2.11)](#general-2.11)
q denotes a value of type XX::const_pointer obtained by conversion from a value p,
- [(2.12)](#general-2.12)
r denotes a value of type T& obtained by the expression *p,
- [(2.13)](#general-2.13)
w denotes a value of type XX::void_pointer obtained by conversion from a value p,
- [(2.14)](#general-2.14)
x denotes a value of type XX::const_void_pointer obtained by conversion from a value q or a value w,
- [(2.15)](#general-2.15)
y denotes a value of type XX::const_void_pointer obtained by conversion from a result value of YY::allocate, or else
a value of type (possibly const) std::nullptr_t,
- [(2.16)](#general-2.16)
n denotes a value of type XX::size_type,
- [(2.17)](#general-2.17)
Args denotes a template parameter pack, and
- [(2.18)](#general-2.18)
args denotes
a function parameter pack with the pattern Args&&[.](#general-2.sentence-1)
[3](#general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2201)
The class template allocator_traits ([[allocator.traits]](allocator.traits "20.2.9Allocator traits")) supplies
a uniform interface to all allocator types[.](#general-3.sentence-1)
This subclause
describes the requirements on allocator types
and thus on types used to instantiate allocator_traits[.](#general-3.sentence-2)
A requirement is optional if a default for a
given type or expression is specified[.](#general-3.sentence-3)
Within the standard library allocator_traits template, an optional requirement that is not supplied by an allocator is
replaced by the specified default type or expression[.](#general-3.sentence-4)
[*Note [1](#general-note-1)*:
There are no program-defined specializations of allocator_traits[.](#general-3.sentence-5)
— *end note*]
[🔗](#general-itemdecl:1)
`typename X::pointer
`
[4](#general-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2221)
*Remarks*: Default: T*
[🔗](#general-itemdecl:2)
`typename X::const_pointer
`
[5](#general-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2231)
*Mandates*: XX::pointer is convertible to XX::const_pointer[.](#general-5.sentence-1)
[6](#general-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2235)
*Remarks*: Default: pointer_traits<XX::pointer>::rebind<const T>
[🔗](#general-itemdecl:3)
`typename X::void_pointer
typename Y::void_pointer
`
[7](#general-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2246)
*Mandates*: XX::pointer is convertible to XX::void_pointer[.](#general-7.sentence-1)
XX::void_pointer and YY::void_pointer are the same type[.](#general-7.sentence-2)
[8](#general-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2251)
*Remarks*: Default:pointer_traits<XX::pointer>::rebind<void>
[🔗](#general-itemdecl:4)
`typename X::const_void_pointer
typename Y::const_void_pointer
`
[9](#general-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2263)
*Mandates*: XX::pointer, XX::const_pointer, and XX::void_pointer are convertible to XX::const_void_pointer[.](#general-9.sentence-1)
XX::const_void_pointer and YY::const_void_pointer are the same type[.](#general-9.sentence-2)
[10](#general-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2270)
*Remarks*: Default:pointer_traits<XX::pointer>::rebind<const void>
[🔗](#general-itemdecl:5)
`typename X::value_type
`
[11](#general-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2281)
*Result*: Identical to T[.](#general-11.sentence-1)
[🔗](#general-itemdecl:6)
`typename X::size_type
`
[12](#general-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2291)
*Result*: An unsigned integer type
that can represent the size of the largest object in the allocation model[.](#general-12.sentence-1)
[13](#general-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2296)
*Remarks*: Default:make_unsigned_t<XX::difference_type>
[🔗](#general-itemdecl:7)
`typename X::difference_type
`
[14](#general-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2307)
*Result*: A signed integer type that can represent
the difference between any two pointers in the allocation model[.](#general-14.sentence-1)
[15](#general-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2312)
*Remarks*: Default:pointer_traits<XX::pointer>::difference_type
[🔗](#general-itemdecl:8)
`typename X::rebind<U>::other
`
[16](#general-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2323)
*Result*: Y
[17](#general-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2327)
*Postconditions*: For all U (including T),YY::rebind_alloc<T> is X[.](#general-17.sentence-1)
[18](#general-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2332)
*Remarks*: If Allocator is a class template instantiation of the formSomeAllocator<T, Args>, where Args is zero or more type
arguments, and Allocator does not supply a rebind member
template, the standard allocator_traits template usesSomeAllocator<U, Args> in place of Allocator::rebind<U>::other by default[.](#general-18.sentence-1)
For allocator types that are not template instantiations of the
above form, no default is provided[.](#general-18.sentence-2)
[19](#general-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2342)
[*Note [2](#general-note-2)*:
The member class template rebind of X is
effectively a typedef template[.](#general-19.sentence-1)
In general, if
the name Allocator is bound to SomeAllocator<T>, thenAllocator::rebind<U>::other is the same type asSomeAllocator<U>, whereSomeAllocator<T>::value_type is T andSomeAllocator<U>::value_type is U[.](#general-19.sentence-2)
— *end note*]
[🔗](#general-itemdecl:9)
`*p
`
[20](#general-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2360)
*Result*: T&
[🔗](#general-itemdecl:10)
`*q
`
[21](#general-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2370)
*Result*: const T&
[22](#general-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2374)
*Postconditions*: *q refers to the same object as *p[.](#general-22.sentence-1)
[🔗](#general-itemdecl:11)
`p->m
`
[23](#general-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2384)
*Result*: Type of T::m[.](#general-23.sentence-1)
[24](#general-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2388)
*Preconditions*: (*p).m is well-defined[.](#general-24.sentence-1)
[25](#general-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2392)
*Effects*: Equivalent to (*p).m[.](#general-25.sentence-1)
[🔗](#general-itemdecl:12)
`q->m
`
[26](#general-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2402)
*Result*: Type of T::m[.](#general-26.sentence-1)
[27](#general-27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2406)
*Preconditions*: (*q).m is well-defined[.](#general-27.sentence-1)
[28](#general-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2410)
*Effects*: Equivalent to (*q).m[.](#general-28.sentence-1)
[🔗](#general-itemdecl:13)
`static_cast<XX::pointer>(w)
`
[29](#general-29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2420)
*Result*: XX::pointer
[30](#general-30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2424)
*Postconditions*: static_cast<XX::pointer>(w) == p[.](#general-30.sentence-1)
[🔗](#general-itemdecl:14)
`static_cast<XX::const_pointer>(x)
`
[31](#general-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2434)
*Result*: XX::const_pointer
[32](#general-32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2438)
*Postconditions*: static_cast<XX::const_pointer>(x) == q[.](#general-32.sentence-1)
[🔗](#general-itemdecl:15)
`pointer_traits<XX::pointer>::pointer_to(r)
`
[33](#general-33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2448)
*Result*: XX::pointer
[34](#general-34)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2452)
*Postconditions*: Same as p[.](#general-34.sentence-1)
[🔗](#general-itemdecl:16)
`a.allocate(n)
`
[35](#general-35)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2462)
*Result*: XX::pointer
[36](#general-36)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2466)
*Effects*: Memory is allocated for an array of n T and such an object is created
but array elements are not constructed[.](#general-36.sentence-1)
[*Example [1](#general-example-1)*:
When reusing storage denoted by some pointer value p,launder(reinterpret_cast<T*>(new (p) byte[n * sizeof(T)])) can be used to implicitly create a suitable array object
and obtain a pointer to it[.](#general-36.sentence-2)
— *end example*]
[37](#general-37)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2478)
*Throws*: allocate may throw an appropriate exception[.](#general-37.sentence-1)
[38](#general-38)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2482)
[*Note [3](#general-note-3)*:
It is intended that a.allocate be an efficient means
of allocating a single object of type T, even when sizeof(T) is small[.](#general-38.sentence-1)
That is, there is no need for a container to maintain its own
free list[.](#general-38.sentence-2)
— *end note*]
[39](#general-39)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2490)
*Remarks*: If n == 0, the return value is unspecified[.](#general-39.sentence-1)
[🔗](#general-itemdecl:17)
`a.allocate(n, y)
`
[40](#general-40)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2500)
*Result*: XX::pointer
[41](#general-41)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2504)
*Effects*: Same as a.allocate(n)[.](#general-41.sentence-1)
The use of y is unspecified, but it is intended as an aid to locality[.](#general-41.sentence-2)
[42](#general-42)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2509)
*Remarks*: Default: a.allocate(n)
[🔗](#general-itemdecl:18)
`a.allocate_at_least(n)
`
[43](#general-43)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2519)
*Result*: allocation_result<XX::pointer, XX::size_type>
[44](#general-44)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2523)
*Returns*: allocation_result<XX::pointer, XX::size_type>{ptr, count} where ptr is memory allocated for an array of count T and such an object is created but array elements are not constructed,
such that count ≥ n[.](#general-44.sentence-1)
If n == 0, the return value is unspecified[.](#general-44.sentence-2)
[45](#general-45)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2531)
*Throws*: allocate_at_least may throw an appropriate exception[.](#general-45.sentence-1)
[46](#general-46)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2535)
*Remarks*: Default: {a.allocate(n), n}[.](#general-46.sentence-1)
[🔗](#general-itemdecl:19)
`a.deallocate(p, n)
`
[47](#general-47)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2545)
*Result*: (not used)
[48](#general-48)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2549)
*Preconditions*:
- [(48.1)](#general-48.1)
If p is memory
that was obtained by a call to a.allocate_at_least,
let ret be the value returned andreq be the value passed as the first argument of that call[.](#general-48.1.sentence-1)
p is equal to ret.ptr andn is a value such thatreq ≤ n ≤ ret.count[.](#general-48.1.sentence-2)
- [(48.2)](#general-48.2)
Otherwise, p is a pointer value obtained from allocate[.](#general-48.2.sentence-1)
n equals the value passed as the first argument
to the invocation of allocate which returned p[.](#general-48.2.sentence-2)
p has not been invalidated by
an intervening call to deallocate[.](#general-48.sentence-2)
[49](#general-49)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2568)
*Throws*: Nothing[.](#general-49.sentence-1)
[🔗](#general-itemdecl:20)
`a.max_size()
`
[50](#general-50)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2578)
*Result*: XX::size_type
[51](#general-51)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2582)
*Returns*: The largest value n that can meaningfully be passed to a.allocate(n)[.](#general-51.sentence-1)
[52](#general-52)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2586)
*Remarks*: Default:numeric_limits<size_type>::max() / sizeof(value_type)
[🔗](#general-itemdecl:21)
`a1 == a2
`
[53](#general-53)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2597)
*Result*: bool
[54](#general-54)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2601)
*Returns*: true only if storage allocated from each can
be deallocated via the other[.](#general-54.sentence-1)
[55](#general-55)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2606)
*Throws*: Nothing[.](#general-55.sentence-1)
[56](#general-56)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2610)
*Remarks*: operator== shall be reflexive, symmetric,
and transitive[.](#general-56.sentence-1)
[🔗](#general-itemdecl:22)
`a1 != a2
`
[57](#general-57)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2621)
*Result*: bool
[58](#general-58)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2625)
*Returns*: !(a1 == a2)[.](#general-58.sentence-1)
[🔗](#general-itemdecl:23)
`a == b
`
[59](#general-59)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2635)
*Result*: bool
[60](#general-60)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2639)
*Returns*: a == YY::rebind_alloc<T>(b)[.](#general-60.sentence-1)
[🔗](#general-itemdecl:24)
`a != b
`
[61](#general-61)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2649)
*Result*: bool
[62](#general-62)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2653)
*Returns*: !(a == b)[.](#general-62.sentence-1)
[🔗](#general-itemdecl:25)
`X u(a);
X u = a;
`
[63](#general-63)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2664)
*Postconditions*: u == a
[64](#general-64)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2668)
*Throws*: Nothing[.](#general-64.sentence-1)
[🔗](#general-itemdecl:26)
`X u(b);
`
[65](#general-65)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2678)
*Postconditions*: Y(u) == b and u == X(b)[.](#general-65.sentence-1)
[66](#general-66)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2682)
*Throws*: Nothing[.](#general-66.sentence-1)
[🔗](#general-itemdecl:27)
`X u(std::move(a));
X u = std::move(a);
`
[67](#general-67)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2693)
*Postconditions*: The value of a is unchanged and is equal to u[.](#general-67.sentence-1)
[68](#general-68)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2697)
*Throws*: Nothing[.](#general-68.sentence-1)
[🔗](#general-itemdecl:28)
`X u(std::move(b));
`
[69](#general-69)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2707)
*Postconditions*: u is equal to the prior value of X(b)[.](#general-69.sentence-1)
[70](#general-70)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2711)
*Throws*: Nothing[.](#general-70.sentence-1)
[🔗](#general-itemdecl:29)
`a.construct(c, args...)
`
[71](#general-71)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2721)
*Result*: (not used)
[72](#general-72)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2725)
*Effects*: Constructs an object of type C at c[.](#general-72.sentence-1)
[73](#general-73)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2729)
*Remarks*: Default:construct_at(c, std::forward<Args>(args)...)
[🔗](#general-itemdecl:30)
`a.destroy(c)
`
[74](#general-74)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2740)
*Result*: (not used)
[75](#general-75)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2744)
*Effects*: Destroys the object at c[.](#general-75.sentence-1)
[76](#general-76)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2748)
*Remarks*: Default: destroy_at(c)
[🔗](#general-itemdecl:31)
`a.select_on_container_copy_construction()
`
[77](#general-77)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2758)
*Result*: X
[78](#general-78)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2762)
*Returns*: Typically returns either a or X()[.](#general-78.sentence-1)
[79](#general-79)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2766)
*Remarks*: Default: return a;
[🔗](#general-itemdecl:32)
`typename X::propagate_on_container_copy_assignment
`
[80](#general-80)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2776)
*Result*: Identical to or derived from true_type or false_type[.](#general-80.sentence-1)
[81](#general-81)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2780)
*Returns*: true_type only if an allocator of type X should be copied
when the client container is copy-assigned;
if so, X shall meet
the [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) and
the copy operation shall not throw exceptions[.](#general-81.sentence-1)
[82](#general-82)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2788)
*Remarks*: Default: false_type
[🔗](#general-itemdecl:33)
`typename X::propagate_on_container_move_assignment
`
[83](#general-83)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2798)
*Result*: Identical to or derived from true_type or false_type[.](#general-83.sentence-1)
[84](#general-84)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2802)
*Returns*: true_type only if an allocator of type X should be moved
when the client container is move-assigned;
if so, X shall meet
the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) and
the move operation shall not throw exceptions[.](#general-84.sentence-1)
[85](#general-85)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2810)
*Remarks*: Default: false_type
[🔗](#general-itemdecl:34)
`typename X::propagate_on_container_swap
`
[86](#general-86)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2820)
*Result*: Identical to or derived from true_type or false_type[.](#general-86.sentence-1)
[87](#general-87)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2824)
*Returns*: true_type only if an allocator of type X should be swapped
when the client container is swapped;
if so,X shall meet the [*Cpp17Swappable*](swappable.requirements#:Cpp17Swappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the swap operation shall not throw exceptions[.](#general-87.sentence-1)
[88](#general-88)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2832)
*Remarks*: Default: false_type
[🔗](#general-itemdecl:35)
`typename X::is_always_equal
`
[89](#general-89)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2842)
*Result*: Identical to or derived from true_type or false_type[.](#general-89.sentence-1)
[90](#general-90)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2846)
*Returns*: true_type only if the expression a1 == a2 is guaranteed
to be true for any two (possibly const) valuesa1, a2 of type X[.](#general-90.sentence-1)
[91](#general-91)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2852)
*Remarks*: Default: is_empty<X>::type
[92](#general-92)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2857)
An allocator type X shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))[.](#general-92.sentence-1)
The XX::pointer, XX::const_pointer, XX::void_pointer, andXX::const_void_pointer types shall meet the*Cpp17NullablePointer* requirements (Table [36](nullablepointer.requirements#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements"))[.](#general-92.sentence-2)
No constructor,
comparison operator function, copy operation, move operation, or swap operation on
these pointer types shall exit via an exception[.](#general-92.sentence-3)
XX::pointer and XX::const_pointer shall also
meet the requirements for
a [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7Random access iterators[random.access.iterators]") ([[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators")) and
the additional requirement that, when p and (p + n) are
dereferenceable pointer values for some integral value n,addressof(*(p + n)) == addressof(*p) + n is true[.](#general-92.sentence-4)
[93](#general-93)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2875)
Let x1 and x2 denote objects of (possibly different) typesXX::void_pointer, XX::const_void_pointer, XX::pointer,
or XX::const_pointer[.](#general-93.sentence-1)
Then, x1 and x2 are[*equivalently-valued*](#def:equivalently-valued "16.4.4.6.1General[allocator.requirements.general]") pointer values, if and only if both x1 and x2 can be explicitly converted to the two corresponding objects px1 and px2 of type XX::const_pointer, using a sequence of static_casts
using only these four types, and the expression px1 == px2 evaluates to true[.](#general-93.sentence-2)
[94](#general-94)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2885)
Let w1 and w2 denote objects of type XX::void_pointer[.](#general-94.sentence-1)
Then for the expressionsw1 == w2
w1 != w2 either or both objects may be replaced by an equivalently-valued object of typeXX::const_void_pointer with no change in semantics[.](#general-94.sentence-2)
[95](#general-95)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2895)
Let p1 and p2 denote objects of type XX::pointer[.](#general-95.sentence-1)
Then for the expressionsp1 == p2
p1 != p2
p1 < p2
p1 <= p2
p1 >= p2
p1 > p2
p1 - p2 either or both objects may be replaced by an equivalently-valued object of typeXX::const_pointer with no change in semantics[.](#general-95.sentence-2)
[96](#general-96)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2910)
An allocator may constrain the types on which it can be instantiated and the
arguments for which its construct or destroy members may be
called[.](#general-96.sentence-1)
If a type cannot be used with a particular allocator, the allocator
class or the call to construct or destroy may fail to instantiate[.](#general-96.sentence-2)
[97](#general-97)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2916)
If the alignment associated with a specific over-aligned type is not
supported by an allocator, instantiation of the allocator for that type may
fail[.](#general-97.sentence-1)
The allocator also may silently ignore the requested alignment[.](#general-97.sentence-2)
[*Note [4](#general-note-4)*:
Additionally, the member function allocate for that type can fail by throwing an object of typebad_alloc[.](#general-97.sentence-3)
— *end note*]
[98](#general-98)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2926)
[*Example [2](#general-example-2)*:
The following is an allocator class template supporting the minimal
interface that meets the requirements of [[allocator.requirements.general]](#general "16.4.4.6.1General"):template<class T>struct SimpleAllocator {using value_type = T;
SimpleAllocator(*ctor args*); template<class U> SimpleAllocator(const SimpleAllocator<U>& other);
T* allocate(std::size_t n); void deallocate(T* p, std::size_t n); template<class U> bool operator==(const SimpleAllocator<U>& rhs) const;};
— *end example*]
[99](#general-99)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2946)
The following exposition-only concept defines
the minimal requirements on an Allocator type[.](#general-99.sentence-1)
template<class Alloc>concept [*simple-allocator*](#concept:simple-allocator "16.4.4.6.1General[allocator.requirements.general]") =requires(Alloc alloc, size_t n) {{ *alloc.allocate(n) } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<typename Alloc::value_type&>; { alloc.deallocate(alloc.allocate(n), n) }; } &&[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]")<Alloc> &&[equality_comparable](concept.equalitycomparable#concept:equality_comparable "18.5.4Concept equality_­comparable[concept.equalitycomparable]")<Alloc>;
A type Alloc models [*simple-allocator*](#concept:simple-allocator "16.4.4.6.1General[allocator.requirements.general]") if it meets the requirements of [[allocator.requirements.general]](#general "16.4.4.6.1General")[.](#general-99.sentence-2)
#### [16.4.4.6.2](#completeness) Allocator completeness requirements [[allocator.requirements.completeness]](allocator.requirements.completeness)
[1](#completeness-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2964)
If X is an allocator class for type T,X additionally meets the allocator completeness requirements if,
whether or not T is a complete type:
- [(1.1)](#completeness-1.1)
X is a complete type, and
- [(1.2)](#completeness-1.2)
all the member types of [allocator_traits<X>](allocator.traits "20.2.9Allocator traits[allocator.traits]") other than value_type are complete types[.](#completeness-1.sentence-1)