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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##### General <a id="allocator.requirements.general">[[allocator.requirements.general]]</a>
2
+
3
+ The library describes a standard set of requirements for *allocators*,
4
+ which are class-type objects that encapsulate the information about an
5
+ allocation model. This information includes the knowledge of pointer
6
+ types, the type of their difference, the type of the size of objects in
7
+ this allocation model, as well as the memory allocation and deallocation
8
+ primitives for it. All of the string types [[strings]], containers
9
+ [[containers]] (except `array`), string buffers and string streams
10
+ [[input.output]], and `match_results` [[re]] are parameterized in terms
11
+ of allocators.
12
+
13
+ In subclause [[allocator.requirements]],
14
+
15
+ - `T`, `U`, `C` denote any cv-unqualified object type
16
+ [[term.object.type]],
17
+ - `X` denotes an allocator class for type `T`,
18
+ - `Y` denotes the corresponding allocator class for type `U`,
19
+ - `XX` denotes the type `allocator_traits<X>`,
20
+ - `YY` denotes the type `allocator_traits<Y>`,
21
+ - `a`, `a1`, `a2` denote lvalues of type `X`,
22
+ - `u` denotes the name of a variable being declared,
23
+ - `b` denotes a value of type `Y`,
24
+ - `c` denotes a pointer of type `C*` through which indirection is valid,
25
+ - `p` denotes a value of type `XX::pointer` obtained by calling
26
+ `a1.allocate`, where `a1 == a`,
27
+ - `q` denotes a value of type `XX::const_pointer` obtained by conversion
28
+ from a value `p`,
29
+ - `r` denotes a value of type `T&` obtained by the expression `*p`,
30
+ - `w` denotes a value of type `XX::void_pointer` obtained by conversion
31
+ from a value `p`,
32
+ - `x` denotes a value of type `XX::const_void_pointer` obtained by
33
+ conversion from a value `q` or a value `w`,
34
+ - `y` denotes a value of type `XX::const_void_pointer` obtained by
35
+ conversion from a result value of `YY::allocate`, or else a value of
36
+ type (possibly const) `std::nullptr_t`,
37
+ - `n` denotes a value of type `XX::size_type`,
38
+ - `Args` denotes a template parameter pack, and
39
+ - `args` denotes a function parameter pack with the pattern `Args&&`.
40
+
41
+ The class template `allocator_traits` [[allocator.traits]] supplies a
42
+ uniform interface to all allocator types. This subclause describes the
43
+ requirements on allocator types and thus on types used to instantiate
44
+ `allocator_traits`. A requirement is optional if a default for a given
45
+ type or expression is specified. Within the standard library
46
+ `allocator_traits` template, an optional requirement that is not
47
+ supplied by an allocator is replaced by the specified default type or
48
+ expression.
49
+
50
+ [*Note 1*: There are no program-defined specializations of
51
+ `allocator_traits`. — *end note*]
52
+
53
+ ``` cpp
54
+ typename X::pointer
55
+ ```
56
+
57
+ *Remarks:* Default: `T*`
58
+
59
+ ``` cpp
60
+ typename X::const_pointer
61
+ ```
62
+
63
+ *Mandates:* `XX::pointer` is convertible to `XX::const_pointer`.
64
+
65
+ *Remarks:* Default: `pointer_traits<XX::pointer>::rebind<const T>`
66
+
67
+ ``` cpp
68
+ typename X::void_pointer
69
+ typename Y::void_pointer
70
+ ```
71
+
72
+ *Mandates:* `XX::pointer` is convertible to `XX::void_pointer`.
73
+ `XX::void_pointer` and `YY::void_pointer` are the same type.
74
+
75
+ *Remarks:* Default: `pointer_traits<XX::pointer>::rebind<void>`
76
+
77
+ ``` cpp
78
+ typename X::const_void_pointer
79
+ typename Y::const_void_pointer
80
+ ```
81
+
82
+ *Mandates:* `XX::pointer`, `XX::const_pointer`, and `XX::void_pointer`
83
+ are convertible to `XX::const_void_pointer`. `XX::const_void_pointer`
84
+ and `YY::const_void_pointer` are the same type.
85
+
86
+ *Remarks:* Default: `pointer_traits<XX::pointer>::rebind<const void>`
87
+
88
+ ``` cpp
89
+ typename X::value_type
90
+ ```
91
+
92
+ *Result:* Identical to `T`.
93
+
94
+ ``` cpp
95
+ typename X::size_type
96
+ ```
97
+
98
+ *Result:* An unsigned integer type that can represent the size of the
99
+ largest object in the allocation model.
100
+
101
+ *Remarks:* Default: `make_unsigned_t<XX::difference_type>`
102
+
103
+ ``` cpp
104
+ typename X::difference_type
105
+ ```
106
+
107
+ *Result:* A signed integer type that can represent the difference
108
+ between any two pointers in the allocation model.
109
+
110
+ *Remarks:* Default: `pointer_traits<XX::pointer>::difference_type`
111
+
112
+ ``` cpp
113
+ typename X::template rebind<U>::other
114
+ ```
115
+
116
+ *Result:* `Y`
117
+
118
+ *Ensures:* For all `U` (including `T`), `YY::rebind_alloc<T>` is `X`.
119
+
120
+ *Remarks:* If `Allocator` is a class template instantiation of the form
121
+ `SomeAllocator<T, Args>`, where `Args` is zero or more type arguments,
122
+ and `Allocator` does not supply a `rebind` member template, the standard
123
+ `allocator_traits` template uses `SomeAllocator<U, Args>` in place of
124
+ `Allocator::rebind<U>::other` by default. For allocator types that are
125
+ not template instantiations of the above form, no default is provided.
126
+
127
+ [*Note 1*: The member class template `rebind` of `X` is effectively a
128
+ typedef template. In general, if the name `Allocator` is bound to
129
+ `SomeAllocator<T>`, then `Allocator::rebind<U>::other` is the same type
130
+ as `SomeAllocator<U>`, where `SomeAllocator<T>::value_type` is `T` and
131
+ `SomeAllocator<U>::value_type` is `U`. — *end note*]
132
+
133
+ ``` cpp
134
+ *p
135
+ ```
136
+
137
+ *Result:* `T&`
138
+
139
+ ``` cpp
140
+ *q
141
+ ```
142
+
143
+ *Result:* `const T&`
144
+
145
+ *Ensures:* `*q` refers to the same object as `*p`.
146
+
147
+ ``` cpp
148
+ p->m
149
+ ```
150
+
151
+ *Result:* Type of `T::m`.
152
+
153
+ *Preconditions:* `(*p).m` is well-defined.
154
+
155
+ *Effects:* Equivalent to `(*p).m`.
156
+
157
+ ``` cpp
158
+ q->m
159
+ ```
160
+
161
+ *Result:* Type of `T::m`.
162
+
163
+ *Preconditions:* `(*q).m` is well-defined.
164
+
165
+ *Effects:* Equivalent to `(*q).m`.
166
+
167
+ ``` cpp
168
+ static_cast<XX::pointer>(w)
169
+ ```
170
+
171
+ *Result:* `XX::pointer`
172
+
173
+ *Ensures:* `static_cast<XX::pointer>(w) == p`.
174
+
175
+ ``` cpp
176
+ static_cast<XX::const_pointer>(x)
177
+ ```
178
+
179
+ *Result:* `XX::const_pointer`
180
+
181
+ *Ensures:* `static_cast<XX::const_pointer>(x) == q`.
182
+
183
+ ``` cpp
184
+ pointer_traits<XX::pointer>::pointer_to(r)
185
+ ```
186
+
187
+ *Result:* `XX::pointer`
188
+
189
+ *Ensures:* Same as `p`.
190
+
191
+ ``` cpp
192
+ a.allocate(n)
193
+ ```
194
+
195
+ *Result:* `XX::pointer`
196
+
197
+ *Effects:* Memory is allocated for an array of `n` `T` and such an
198
+ object is created but array elements are not constructed.
199
+
200
+ [*Example 1*: When reusing storage denoted by some pointer value `p`,
201
+ `launder(reinterpret_cast<T*>(new (p) byte[n * sizeof(T)]))` can be used
202
+ to implicitly create a suitable array object and obtain a pointer to
203
+ it. — *end example*]
204
+
205
+ *Throws:* `allocate` may throw an appropriate exception.
206
+
207
+ [*Note 2*: It is intended that `a.allocate` be an efficient means of
208
+ allocating a single object of type `T`, even when `sizeof(T)` is small.
209
+ That is, there is no need for a container to maintain its own free
210
+ list. — *end note*]
211
+
212
+ *Remarks:* If `n == 0`, the return value is unspecified.
213
+
214
+ ``` cpp
215
+ a.allocate(n, y)
216
+ ```
217
+
218
+ *Result:* `XX::pointer`
219
+
220
+ *Effects:* Same as `a.allocate(n)`. The use of `y` is unspecified, but
221
+ it is intended as an aid to locality.
222
+
223
+ *Remarks:* Default: `a.allocate(n)`
224
+
225
+ ``` cpp
226
+ a.allocate_at_least(n)
227
+ ```
228
+
229
+ *Result:* `allocation_result<XX::pointer, XX::size_type>`
230
+
231
+ *Returns:* `allocation_result<XX::pointer, XX::size_type>{ptr, count}`
232
+ where `ptr` is memory allocated for an array of `count` `T` and such an
233
+ object is created but array elements are not constructed, such that
234
+ `count` ≥ `n`. If `n == 0`, the return value is unspecified.
235
+
236
+ *Throws:* `allocate_at_least` may throw an appropriate exception.
237
+
238
+ *Remarks:* Default: `{a.allocate(n), n}`.
239
+
240
+ ``` cpp
241
+ a.deallocate(p, n)
242
+ ```
243
+
244
+ *Result:* (not used)
245
+
246
+ *Preconditions:*
247
+
248
+ - If `p` is memory that was obtained by a call to `a.allocate_at_least`,
249
+ let `ret` be the value returned and `req` be the value passed as the
250
+ first argument of that call. `p` is equal to `ret.ptr` and `n` is a
251
+ value such that `req` ≤ `n` ≤ `ret.count`.
252
+ - Otherwise, `p` is a pointer value obtained from `allocate`. `n` equals
253
+ the value passed as the first argument to the invocation of `allocate`
254
+ which returned `p`.
255
+
256
+ `p` has not been invalidated by an intervening call to `deallocate`.
257
+
258
+ *Throws:* Nothing.
259
+
260
+ ``` cpp
261
+ a.max_size()
262
+ ```
263
+
264
+ *Result:* `XX::size_type`
265
+
266
+ *Returns:* The largest value `n` that can meaningfully be passed to
267
+ `a.allocate(n)`.
268
+
269
+ *Remarks:* Default:
270
+ `numeric_limits<size_type>::max() / sizeof(value_type)`
271
+
272
+ ``` cpp
273
+ a1 == a2
274
+ ```
275
+
276
+ *Result:* `bool`
277
+
278
+ *Returns:* `true` only if storage allocated from each can be deallocated
279
+ via the other.
280
+
281
+ *Throws:* Nothing.
282
+
283
+ *Remarks:* `operator==` shall be reflexive, symmetric, and transitive.
284
+
285
+ ``` cpp
286
+ a1 != a2
287
+ ```
288
+
289
+ *Result:* `bool`
290
+
291
+ *Returns:* `!(a1 == a2)`.
292
+
293
+ ``` cpp
294
+ a == b
295
+ ```
296
+
297
+ *Result:* `bool`
298
+
299
+ *Returns:* `a == YY::rebind_alloc<T>(b)`.
300
+
301
+ ``` cpp
302
+ a != b
303
+ ```
304
+
305
+ *Result:* `bool`
306
+
307
+ *Returns:* `!(a == b)`.
308
+
309
+ ``` cpp
310
+ X u(a);
311
+ X u = a;
312
+ ```
313
+
314
+ *Ensures:* `u == a`
315
+
316
+ *Throws:* Nothing.
317
+
318
+ ``` cpp
319
+ X u(b);
320
+ ```
321
+
322
+ *Ensures:* `Y(u) == b` and `u == X(b)`.
323
+
324
+ *Throws:* Nothing.
325
+
326
+ ``` cpp
327
+ X u(std::move(a));
328
+ X u = std::move(a);
329
+ ```
330
+
331
+ *Ensures:* The value of `a` is unchanged and is equal to `u`.
332
+
333
+ *Throws:* Nothing.
334
+
335
+ ``` cpp
336
+ X u(std::move(b));
337
+ ```
338
+
339
+ *Ensures:* `u` is equal to the prior value of `X(b)`.
340
+
341
+ *Throws:* Nothing.
342
+
343
+ ``` cpp
344
+ a.construct(c, args)
345
+ ```
346
+
347
+ *Result:* (not used)
348
+
349
+ *Effects:* Constructs an object of type `C` at `c`.
350
+
351
+ *Remarks:* Default: `construct_at(c, std::forward<Args>(args)...)`
352
+
353
+ ``` cpp
354
+ a.destroy(c)
355
+ ```
356
+
357
+ *Result:* (not used)
358
+
359
+ *Effects:* Destroys the object at `c`.
360
+
361
+ *Remarks:* Default: `destroy_at(c)`
362
+
363
+ ``` cpp
364
+ a.select_on_container_copy_construction()
365
+ ```
366
+
367
+ *Result:* `X`
368
+
369
+ *Returns:* Typically returns either `a` or `X()`.
370
+
371
+ *Remarks:* Default: `return a;`
372
+
373
+ ``` cpp
374
+ typename X::propagate_on_container_copy_assignment
375
+ ```
376
+
377
+ *Result:* Identical to or derived from `true_type` or `false_type`.
378
+
379
+ *Returns:* `true_type` only if an allocator of type `X` should be copied
380
+ when the client container is copy-assigned; if so, `X` shall meet the
381
+ *Cpp17CopyAssignable* requirements ([[cpp17.copyassignable]]) and the
382
+ copy operation shall not throw exceptions.
383
+
384
+ *Remarks:* Default: `false_type`
385
+
386
+ ``` cpp
387
+ typename X::propagate_on_container_move_assignment
388
+ ```
389
+
390
+ *Result:* Identical to or derived from `true_type` or `false_type`.
391
+
392
+ *Returns:* `true_type` only if an allocator of type `X` should be moved
393
+ when the client container is move-assigned; if so, `X` shall meet the
394
+ *Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]) and the
395
+ move operation shall not throw exceptions.
396
+
397
+ *Remarks:* Default: `false_type`
398
+
399
+ ``` cpp
400
+ typename X::propagate_on_container_swap
401
+ ```
402
+
403
+ *Result:* Identical to or derived from `true_type` or `false_type`.
404
+
405
+ *Returns:* `true_type` only if an allocator of type `X` should be
406
+ swapped when the client container is swapped; if so, `X` shall meet the
407
+ *Cpp17Swappable* requirements [[swappable.requirements]] and the `swap`
408
+ operation shall not throw exceptions.
409
+
410
+ *Remarks:* Default: `false_type`
411
+
412
+ ``` cpp
413
+ typename X::is_always_equal
414
+ ```
415
+
416
+ *Result:* Identical to or derived from `true_type` or `false_type`.
417
+
418
+ *Returns:* `true_type` only if the expression `a1 == a2` is guaranteed
419
+ to be `true` for any two (possibly const) values `a1`, `a2` of type `X`.
420
+
421
+ *Remarks:* Default: `is_empty<X>::type`
422
+
423
+ An allocator type `X` shall meet the *Cpp17CopyConstructible*
424
+ requirements ([[cpp17.copyconstructible]]). The `XX::pointer`,
425
+ `XX::const_pointer`, `XX::void_pointer`, and `XX::const_void_pointer`
426
+ types shall meet the *Cpp17NullablePointer* requirements (
427
+ [[cpp17.nullablepointer]]). No constructor, comparison operator
428
+ function, copy operation, move operation, or swap operation on these
429
+ pointer types shall exit via an exception. `XX::pointer` and
430
+ `XX::const_pointer` shall also meet the requirements for a
431
+ *Cpp17RandomAccessIterator* [[random.access.iterators]] and the
432
+ additional requirement that, when `p` and `(p + n)` are dereferenceable
433
+ pointer values for some integral value `n`,
434
+
435
+ ``` cpp
436
+ addressof(*(p + n)) == addressof(*p) + n
437
+ ```
438
+
439
+ is `true`.
440
+
441
+ Let `x1` and `x2` denote objects of (possibly different) types
442
+ `XX::void_pointer`, `XX::const_void_pointer`, `XX::pointer`, or
443
+ `XX::const_pointer`. Then, `x1` and `x2` are *equivalently-valued*
444
+ pointer values, if and only if both `x1` and `x2` can be explicitly
445
+ converted to the two corresponding objects `px1` and `px2` of type
446
+ `XX::const_pointer`, using a sequence of `static_cast`s using only these
447
+ four types, and the expression `px1 == px2` evaluates to `true`.
448
+
449
+ Let `w1` and `w2` denote objects of type `XX::void_pointer`. Then for
450
+ the expressions
451
+
452
+ ``` cpp
453
+ w1 == w2
454
+ w1 != w2
455
+ ```
456
+
457
+ either or both objects may be replaced by an equivalently-valued object
458
+ of type `XX::const_void_pointer` with no change in semantics.
459
+
460
+ Let `p1` and `p2` denote objects of type `XX::pointer`. Then for the
461
+ expressions
462
+
463
+ ``` cpp
464
+ p1 == p2
465
+ p1 != p2
466
+ p1 < p2
467
+ p1 <= p2
468
+ p1 >= p2
469
+ p1 > p2
470
+ p1 - p2
471
+ ```
472
+
473
+ either or both objects may be replaced by an equivalently-valued object
474
+ of type `XX::const_pointer` with no change in semantics.
475
+
476
+ An allocator may constrain the types on which it can be instantiated and
477
+ the arguments for which its `construct` or `destroy` members may be
478
+ called. If a type cannot be used with a particular allocator, the
479
+ allocator class or the call to `construct` or `destroy` may fail to
480
+ instantiate.
481
+
482
+ If the alignment associated with a specific over-aligned type is not
483
+ supported by an allocator, instantiation of the allocator for that type
484
+ may fail. The allocator also may silently ignore the requested
485
+ alignment.
486
+
487
+ [*Note 2*: Additionally, the member function `allocate` for that type
488
+ can fail by throwing an object of type `bad_alloc`. — *end note*]
489
+
490
+ [*Example 1*:
491
+
492
+ The following is an allocator class template supporting the minimal
493
+ interface that meets the requirements of
494
+ [[allocator.requirements.general]]:
495
+
496
+ ``` cpp
497
+ template<class T>
498
+ struct SimpleAllocator {
499
+ using value_type = T;
500
+ SimpleAllocator(ctor args);
501
+
502
+ template<class U> SimpleAllocator(const SimpleAllocator<U>& other);
503
+
504
+ T* allocate(std::size_t n);
505
+ void deallocate(T* p, std::size_t n);
506
+
507
+ template<class U> bool operator==(const SimpleAllocator<U>& rhs) const;
508
+ };
509
+ ```
510
+
511
+ — *end example*]
512
+