From Jason Turner

[memory]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpl58frcar/{from.md → to.md} +466 -386
tmp/tmpl58frcar/{from.md → to.md} RENAMED
@@ -1,19 +1,19 @@
1
  ## Memory <a id="memory">[[memory]]</a>
2
 
3
  ### In general <a id="memory.general">[[memory.general]]</a>
4
 
5
  This subclause describes the contents of the header `<memory>` (
6
- [[memory.syn]]) and some of the contents of the C headers `<cstdlib>`
7
- and `<cstring>` ([[c.malloc]]).
8
 
9
  ### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
10
 
11
  The header `<memory>` defines several types and function templates that
12
  describe properties of pointers and pointer-like types, manage memory
13
- for containers and other template types, and construct multiple objects
14
- in uninitialized memory buffers ([[pointer.traits]]–
15
  [[specialized.algorithms]]). The header also defines the templates
16
  `unique_ptr`, `shared_ptr`, `weak_ptr`, and various function templates
17
  that operate on objects of these types ([[smartptr]]).
18
 
19
  ``` cpp
@@ -29,55 +29,106 @@ namespace std {
29
  void declare_no_pointers(char* p, size_t n);
30
  void undeclare_no_pointers(char* p, size_t n);
31
  pointer_safety get_pointer_safety() noexcept;
32
 
33
  // [ptr.align], pointer alignment function
34
- void* align(std::size_t alignment, std::size_t size,
35
- void*& ptr, std::size_t& space);
36
 
37
  // [allocator.tag], allocator argument tag
38
- struct allocator_arg_t { };
39
- constexpr allocator_arg_t allocator_arg{};
40
 
41
  // [allocator.uses], uses_allocator
42
  template <class T, class Alloc> struct uses_allocator;
43
 
44
  // [allocator.traits], allocator traits
45
  template <class Alloc> struct allocator_traits;
46
 
47
- // [default.allocator], the default allocator:
48
  template <class T> class allocator;
49
- template <> class allocator<void>;
50
  template <class T, class U>
51
  bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
52
  template <class T, class U>
53
  bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
54
 
55
- // [storage.iterator], raw storage iterator:
56
- template <class OutputIterator, class T> class raw_storage_iterator;
57
-
58
- // [temporary.buffer], temporary buffers:
59
- template <class T>
60
- pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
61
- template <class T>
62
- void return_temporary_buffer(T* p);
63
-
64
- // [specialized.algorithms], specialized algorithms:
65
- template <class T> T* addressof(T& r) noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
66
  template <class InputIterator, class ForwardIterator>
67
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
68
  ForwardIterator result);
 
 
 
 
69
  template <class InputIterator, class Size, class ForwardIterator>
70
  ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
71
  ForwardIterator result);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  template <class ForwardIterator, class T>
73
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
74
  const T& x);
 
 
 
 
75
  template <class ForwardIterator, class Size, class T>
76
  ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- // [unique.ptr] class template unique_ptr:
79
  template <class T> struct default_delete;
80
  template <class T> struct default_delete<T[]>;
81
  template <class T, class D = default_delete<T>> class unique_ptr;
82
  template <class T, class D> class unique_ptr<T[], D>;
83
 
@@ -123,34 +174,35 @@ namespace std {
123
  template <class T, class D>
124
  bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
125
  template <class T, class D>
126
  bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
127
 
128
- // [util.smartptr.weakptr], class bad_weak_ptr:
129
  class bad_weak_ptr;
130
 
131
- // [util.smartptr.shared], class template shared_ptr:
132
  template<class T> class shared_ptr;
133
 
134
  // [util.smartptr.shared.create], shared_ptr creation
135
- template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
 
136
  template<class T, class A, class... Args>
137
  shared_ptr<T> allocate_shared(const A& a, Args&&... args);
138
 
139
- // [util.smartptr.shared.cmp], shared_ptr comparisons:
140
  template<class T, class U>
141
- bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
142
  template<class T, class U>
143
- bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
144
  template<class T, class U>
145
- bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
146
  template<class T, class U>
147
- bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
148
  template<class T, class U>
149
- bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
150
  template<class T, class U>
151
- bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
152
 
153
  template <class T>
154
  bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
155
  template <class T>
156
  bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
@@ -173,41 +225,43 @@ namespace std {
173
  template <class T>
174
  bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
175
  template <class T>
176
  bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
177
 
178
- // [util.smartptr.shared.spec], shared_ptr specialized algorithms:
179
- template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
 
180
 
181
- // [util.smartptr.shared.cast], shared_ptr casts:
182
  template<class T, class U>
183
- shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
184
  template<class T, class U>
185
- shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
186
  template<class T, class U>
187
- shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
188
 
189
- // [util.smartptr.getdeleter], shared_ptr get_deleter:
190
- template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
 
191
 
192
- // [util.smartptr.shared.io], shared_ptr I/O:
193
  template<class E, class T, class Y>
194
- basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
195
 
196
- // [util.smartptr.weak], class template weak_ptr:
197
  template<class T> class weak_ptr;
198
 
199
- // [util.smartptr.weak.spec], weak_ptr specialized algorithms:
200
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
201
 
202
- // [util.smartptr.ownerless], class template owner_less:
203
- template<class T> class owner_less;
204
 
205
- // [util.smartptr.enab], class template enable_shared_from_this:
206
  template<class T> class enable_shared_from_this;
207
 
208
- // [util.smartptr.shared.atomic], shared_ptr atomic access:
209
  template<class T>
210
  bool atomic_is_lock_free(const shared_ptr<T>* p);
211
 
212
  template<class T>
213
  shared_ptr<T> atomic_load(const shared_ptr<T>* p);
@@ -220,12 +274,11 @@ namespace std {
220
  void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
221
 
222
  template<class T>
223
  shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
224
  template<class T>
225
- shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r,
226
- memory_order mo);
227
 
228
  template<class T>
229
  bool atomic_compare_exchange_weak(
230
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
231
  template<class T>
@@ -238,17 +291,18 @@ namespace std {
238
  template<class T>
239
  bool atomic_compare_exchange_strong_explicit(
240
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
241
  memory_order success, memory_order failure);
242
 
243
- // [util.smartptr.hash] hash support
244
  template <class T> struct hash;
245
  template <class T, class D> struct hash<unique_ptr<T, D>>;
246
  template <class T> struct hash<shared_ptr<T>>;
247
 
248
- // [depr.auto.ptr], auto_ptr (deprecated)
249
- template <class X> class auto_ptr;
 
250
  }
251
  ```
252
 
253
  ### Pointer traits <a id="pointer.traits">[[pointer.traits]]</a>
254
 
@@ -256,23 +310,23 @@ The class template `pointer_traits` supplies a uniform interface to
256
  certain attributes of pointer-like types.
257
 
258
  ``` cpp
259
  namespace std {
260
  template <class Ptr> struct pointer_traits {
261
- typedef Ptr pointer;
262
- typedef see below element_type;
263
- typedef see below difference_type;
264
 
265
  template <class U> using rebind = see below;
266
 
267
  static pointer pointer_to(see below r);
268
  };
269
 
270
  template <class T> struct pointer_traits<T*> {
271
- typedef T* pointer;
272
- typedef T element_type;
273
- typedef ptrdiff_t difference_type;
274
 
275
  template <class U> using rebind = U*;
276
 
277
  static pointer pointer_to(see below r) noexcept;
278
  };
@@ -280,49 +334,53 @@ namespace std {
280
  ```
281
 
282
  #### Pointer traits member types <a id="pointer.traits.types">[[pointer.traits.types]]</a>
283
 
284
  ``` cpp
285
- typedef see below element_type;
286
  ```
287
 
288
- *Type:* `Ptr::element_type` if such a type exists; otherwise, `T` if
289
- `Ptr` is a class template instantiation of the form
290
- `SomePointer<T, Args>`, where `Args` is zero or more type arguments;
291
- otherwise, the specialization is ill-formed.
 
292
 
293
  ``` cpp
294
- typedef see below difference_type;
295
  ```
296
 
297
- *Type:* `Ptr::difference_type` if such a type exists; otherwise,
298
- `std::ptrdiff_t`.
 
299
 
300
  ``` cpp
301
  template <class U> using rebind = see below;
302
  ```
303
 
304
- *Alias template:* `Ptr::rebind<U>` if such a type exists; otherwise,
305
- `SomePointer<U, Args>` if `Ptr` is a class template instantiation of the
306
- form `SomePointer<T, Args>`, where `Args` is zero or more type
307
- arguments; otherwise, the instantiation of `rebind` is ill-formed.
 
 
308
 
309
  #### Pointer traits member functions <a id="pointer.traits.functions">[[pointer.traits.functions]]</a>
310
 
311
  ``` cpp
312
  static pointer pointer_traits::pointer_to(see below r);
313
  static pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
314
  ```
315
 
316
- If `element_type` is (possibly cv-qualified) `void`, the type of `r` is
317
  unspecified; otherwise, it is `element_type&`.
318
 
319
  *Returns:* The first member function returns a pointer to `r` obtained
320
  by calling `Ptr::pointer_to(r)` through which indirection is valid; an
321
  instantiation of this function is ill-formed if `Ptr` does not have a
322
  matching `pointer_to` static member function. The second member function
323
- returns `std::addressof(r)`.
324
 
325
  ### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
326
 
327
  A complete object is *declared reachable* while the number of calls to
328
  `declare_reachable` with an argument referencing the object exceeds the
@@ -337,13 +395,12 @@ void declare_reachable(void* p);
337
  pointer ([[basic.stc.dynamic.safety]]) or a null pointer value.
338
 
339
  *Effects:* If `p` is not null, the complete object referenced by `p` is
340
  subsequently declared reachable ([[basic.stc.dynamic.safety]]).
341
 
342
- *Throws:* May throw `std::bad_alloc` if the system cannot allocate
343
- additional memory that may be required to track objects declared
344
- reachable.
345
 
346
  ``` cpp
347
  template <class T> T* undeclare_reachable(T* p);
348
  ```
349
 
@@ -355,38 +412,43 @@ live ([[basic.life]]) from the time of the call until the last
355
  *Returns:* A safely derived copy of `p` which shall compare equal to
356
  `p`.
357
 
358
  *Throws:* Nothing.
359
 
360
- It is expected that calls to `declare_reachable(p)` will consume a small
361
- amount of memory in addition to that occupied by the referenced object
362
- until the matching call to `undeclare_reachable(p)` is encountered. Long
363
- running programs should arrange that calls are matched.
 
364
 
365
  ``` cpp
366
  void declare_no_pointers(char* p, size_t n);
367
  ```
368
 
369
  *Requires:* No bytes in the specified range are currently registered
370
  with `declare_no_pointers()`. If the specified range is in an allocated
371
  object, then it must be entirely within a single allocated object. The
372
  object must be live until the corresponding `undeclare_no_pointers()`
373
- call. In a garbage-collecting implementation, the fact that a region in
374
- an object is registered with `declare_no_pointers()` should not prevent
375
- the object from being collected.
 
 
376
 
377
  *Effects:* The `n` bytes starting at `p` no longer contain traceable
378
  pointer locations, independent of their type. Hence indirection through
379
  a pointer located there is undefined if the object it points to was
380
  created by global `operator new` and not previously declared reachable.
381
- This may be used to inform a garbage collector or leak detector that
382
- this region of memory need not be traced.
 
383
 
384
  *Throws:* Nothing.
385
 
386
- Under some conditions implementations may need to allocate memory.
387
- However, the request can be ignored if memory allocation fails.
 
388
 
389
  ``` cpp
390
  void undeclare_no_pointers(char* p, size_t n);
391
  ```
392
 
@@ -402,47 +464,46 @@ ends.
402
  ``` cpp
403
  pointer_safety get_pointer_safety() noexcept;
404
  ```
405
 
406
  *Returns:* `pointer_safety::strict` if the implementation has strict
407
- pointer safety ([[basic.stc.dynamic.safety]]). It is implementation
408
- defined whether `get_pointer_safety` returns `pointer_safety::relaxed`
409
- or `pointer_safety::preferred` if the implementation has relaxed pointer
410
- safety.[^1]
411
 
412
  ### Align <a id="ptr.align">[[ptr.align]]</a>
413
 
414
  ``` cpp
415
- void* align(std::size_t alignment, std::size_t size,
416
- void*& ptr, std::size_t& space);
417
  ```
418
 
419
  *Effects:* If it is possible to fit `size` bytes of storage aligned by
420
  `alignment` into the buffer pointed to by `ptr` with length `space`, the
421
- function updates `ptr` to point to the first possible address of such
422
  storage and decreases `space` by the number of bytes used for alignment.
423
  Otherwise, the function does nothing.
424
 
425
  *Requires:*
426
 
427
- - `alignment` shall be a fundamental alignment value or an extended
428
- alignment value supported by the implementation in this context
429
- - `ptr` shall point to contiguous storage of at least `space` bytes
430
 
431
  *Returns:* A null pointer if the requested aligned buffer would not fit
432
  into the available space, otherwise the adjusted value of `ptr`.
433
 
434
- The function updates its `ptr` and `space` arguments so that it can be
435
- called repeatedly with possibly different `alignment` and `size`
436
- arguments for the same buffer.
437
 
438
  ### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
439
 
440
  ``` cpp
441
  namespace std {
442
- struct allocator_arg_t { };
443
- constexpr allocator_arg_t allocator_arg{};
444
  }
445
  ```
446
 
447
  The `allocator_arg_t` struct is an empty structure type used as a unique
448
  type to disambiguate constructor and function overloading. Specifically,
@@ -457,74 +518,77 @@ argument of a type that satisfies the `Allocator` requirements (
457
 
458
  ``` cpp
459
  template <class T, class Alloc> struct uses_allocator;
460
  ```
461
 
462
- automatically detects whether `T` has a nested `allocator_type` that is
463
- convertible from `Alloc`. Meets the BinaryTypeTrait
464
- requirements ([[meta.rqmts]]). The implementation shall provide a
465
- definition that is derived from `true_type` if a type
466
- `T::allocator_type` exists and
467
- `is_convertible<Alloc, T::allocator_type>::value != false`, otherwise it
 
468
  shall be derived from `false_type`. A program may specialize this
469
  template to derive from `true_type` for a user-defined type `T` that
470
  does not have a nested `allocator_type` but nonetheless can be
471
  constructed with an allocator where either:
472
 
473
  - the first argument of a constructor has type `allocator_arg_t` and the
474
  second argument has type `Alloc` or
475
  - the last argument of a constructor has type `Alloc`.
476
 
477
- #### uses-allocator construction <a id="allocator.uses.construction">[[allocator.uses.construction]]</a>
478
 
479
  *Uses-allocator construction* with allocator `Alloc` refers to the
480
  construction of an object `obj` of type `T`, using constructor arguments
481
  `v1, v2, ..., vN` of types `V1, V2, ..., VN`, respectively, and an
482
  allocator `alloc` of type `Alloc`, according to the following rules:
483
 
484
- - if `uses_allocator<T, Alloc>::value` is `false` and
485
- `is_constructible<T, V1, V2, ..., VN>::value` is `true`, then `obj` is
486
  initialized as `obj(v1, v2, ..., vN)`;
487
- - otherwise, if `uses_allocator<T, Alloc>::value` is `true` and
488
- `is_constructible<T, allocator_arg_t, Alloc,`
489
- `V1, V2, ..., VN>::value` is `true`, then `obj` is initialized as
490
- `obj(allocator_arg, alloc, v1,
491
  v2, ..., vN)`;
492
- - otherwise, if `uses_allocator<T, Alloc>::value` is `true` and
493
- `is_constructible<T, V1, V2, ..., VN, Alloc>::value` is `true`, then
494
- `obj` is initialized as `obj(v1, v2, ..., vN, alloc)`;
495
  - otherwise, the request for uses-allocator construction is ill-formed.
496
- An error will result if `uses_allocator<T, Alloc>::value` is `true`
497
- but the specific constructor does not take an allocator. This
498
  definition prevents a silent failure to pass the allocator to an
499
- element.
500
 
501
  ### Allocator traits <a id="allocator.traits">[[allocator.traits]]</a>
502
 
503
  The class template `allocator_traits` supplies a uniform interface to
504
  all allocator types. An allocator cannot be a non-class type, however,
505
- even if `allocator_traits` supplies the entire required interface. Thus,
506
- it is always possible to create a derived class from an allocator.
 
 
507
 
508
  ``` cpp
509
  namespace std {
510
  template <class Alloc> struct allocator_traits {
511
- typedef Alloc allocator_type;
512
 
513
- typedef typename Alloc::value_type value_type;
514
 
515
- typedef see below pointer;
516
- typedef see below const_pointer;
517
- typedef see below void_pointer;
518
- typedef see below const_void_pointer;
519
 
520
- typedef see below difference_type;
521
- typedef see below size_type;
522
 
523
- typedef see below propagate_on_container_copy_assignment;
524
- typedef see below propagate_on_container_move_assignment;
525
- typedef see below propagate_on_container_swap;
 
526
 
527
  template <class T> using rebind_alloc = see below;
528
  template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
529
 
530
  static pointer allocate(Alloc& a, size_type n);
@@ -546,80 +610,99 @@ namespace std {
546
  ```
547
 
548
  #### Allocator traits member types <a id="allocator.traits.types">[[allocator.traits.types]]</a>
549
 
550
  ``` cpp
551
- typedef see below pointer;
552
  ```
553
 
554
- *Type:* `Alloc::pointer` if such a type exists; otherwise,
555
- `value_type*`.
556
 
557
  ``` cpp
558
- typedef see below const_pointer;
559
  ```
560
 
561
- *Type:* `Alloc::const_pointer` if such a type exists; otherwise,
562
- `pointer_traits<pointer>::rebind<const value_type>`.
 
563
 
564
  ``` cpp
565
- typedef see below void_pointer;
566
  ```
567
 
568
- *Type:* `Alloc::void_pointer` if such a type exists; otherwise,
569
- `pointer_traits<pointer>::rebind<void>`.
 
570
 
571
  ``` cpp
572
- typedef see below const_void_pointer;
573
  ```
574
 
575
- *Type:* `Alloc::const_void_pointer` if such a type exists; otherwise,
 
 
576
  `pointer_traits<pointer>::rebind<const void>`.
577
 
578
  ``` cpp
579
- typedef see below difference_type;
580
  ```
581
 
582
- *Type:* `Alloc::difference_type` if such a type exists; otherwise,
583
- `pointer_traits<pointer>::difference_type`.
 
584
 
585
  ``` cpp
586
- typedef see below size_type;
587
  ```
588
 
589
- *Type:* `Alloc::size_type` if such a type exists; otherwise,
 
590
  `make_unsigned_t<difference_type>`.
591
 
592
  ``` cpp
593
- typedef see below propagate_on_container_copy_assignment;
594
  ```
595
 
596
- *Type:* `Alloc::propagate_on_container_copy_assignment` if such a type
597
- exists, otherwise `false_type`.
 
598
 
599
  ``` cpp
600
- typedef see below propagate_on_container_move_assignment;
601
  ```
602
 
603
- *Type:* `Alloc::propagate_on_container_move_assignment` if such a type
604
- exists, otherwise `false_type`.
 
605
 
606
  ``` cpp
607
- typedef see below propagate_on_container_swap;
608
  ```
609
 
610
- *Type:* `Alloc::propagate_on_container_swap` if such a type exists,
611
- otherwise `false_type`.
 
 
 
 
 
 
 
 
 
612
 
613
  ``` cpp
614
  template <class T> using rebind_alloc = see below;
615
  ```
616
 
617
- *Alias template:* `Alloc::rebind<T>::other` if such a type exists;
618
- otherwise, `Alloc<T, Args>` if `Alloc` is a class template instantiation
619
- of the form `Alloc<U, Args>`, where `Args` is zero or more type
620
- arguments; otherwise, the instantiation of `rebind_alloc` is ill-formed.
 
 
621
 
622
  #### Allocator traits static member functions <a id="allocator.traits.members">[[allocator.traits.members]]</a>
623
 
624
  ``` cpp
625
  static pointer allocate(Alloc& a, size_type n);
@@ -636,90 +719,65 @@ otherwise, `a.allocate(n)`.
636
 
637
  ``` cpp
638
  static void deallocate(Alloc& a, pointer p, size_type n);
639
  ```
640
 
641
- *Effects:* calls `a.deallocate(p, n)`.
642
 
643
  *Throws:* Nothing.
644
 
645
  ``` cpp
646
  template <class T, class... Args>
647
  static void construct(Alloc& a, T* p, Args&&... args);
648
  ```
649
 
650
- *Effects:* calls `a.construct(p, std::forward<Args>(args)...)` if that
651
  call is well-formed; otherwise, invokes
652
  `::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)`.
653
 
654
  ``` cpp
655
  template <class T>
656
  static void destroy(Alloc& a, T* p);
657
  ```
658
 
659
- *Effects:* calls `a.destroy(p)` if that call is well-formed; otherwise,
660
  invokes `p->~T()`.
661
 
662
  ``` cpp
663
  static size_type max_size(const Alloc& a) noexcept;
664
  ```
665
 
666
  *Returns:* `a.max_size()` if that expression is well-formed; otherwise,
667
- `numeric_limits<size_type>::max()`.
668
 
669
  ``` cpp
670
  static Alloc select_on_container_copy_construction(const Alloc& rhs);
671
  ```
672
 
673
  *Returns:* `rhs.select_on_container_copy_construction()` if that
674
  expression is well-formed; otherwise, `rhs`.
675
 
676
  ### The default allocator <a id="default.allocator">[[default.allocator]]</a>
677
 
 
 
 
678
  ``` cpp
679
  namespace std {
680
- template <class T> class allocator;
681
-
682
- // specialize for void:
683
- template <> class allocator<void> {
684
- public:
685
- typedef void* pointer;
686
- typedef const void* const_pointer;
687
- // reference-to-void members are impossible.
688
- typedef void value_type;
689
- template <class U> struct rebind { typedef allocator<U> other; };
690
- };
691
-
692
  template <class T> class allocator {
693
  public:
694
- typedef size_t size_type;
695
- typedef ptrdiff_t difference_type;
696
- typedef T* pointer;
697
- typedef const T* const_pointer;
698
- typedef T& reference;
699
- typedef const T& const_reference;
700
- typedef T value_type;
701
- template <class U> struct rebind { typedef allocator<U> other; };
702
- typedef true_type propagate_on_container_move_assignment;
703
 
704
  allocator() noexcept;
705
  allocator(const allocator&) noexcept;
706
  template <class U> allocator(const allocator<U>&) noexcept;
707
  ~allocator();
708
 
709
- pointer address(reference x) const noexcept;
710
- const_pointer address(const_reference x) const noexcept;
711
-
712
- pointer allocate(
713
- size_type, allocator<void>::const_pointer hint = 0);
714
- void deallocate(pointer p, size_type n);
715
- size_type max_size() const noexcept;
716
-
717
- template<class U, class... Args>
718
- void construct(U* p, Args&&... args);
719
- template <class U>
720
- void destroy(U* p);
721
  };
722
  }
723
  ```
724
 
725
  #### `allocator` members <a id="allocator.members">[[allocator.members]]</a>
@@ -730,300 +788,322 @@ concurrent calls to those member functions from different threads. Calls
730
  to these functions that allocate or deallocate a particular unit of
731
  storage shall occur in a single total order, and each such deallocation
732
  call shall happen before the next allocation (if any) in this order.
733
 
734
  ``` cpp
735
- pointer address(reference x) const noexcept;
736
  ```
737
 
738
- *Returns:* The actual address of the object referenced by `x`, even in
739
- the presence of an overloaded operator&.
740
-
741
- ``` cpp
742
- const_pointer address(const_reference x) const noexcept;
743
- ```
744
-
745
- *Returns:* The actual address of the object referenced by `x`, even in
746
- the presence of an overloaded operator&.
747
-
748
- ``` cpp
749
- pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
750
- ```
751
-
752
- In a container member function, the address of an adjacent element is
753
- often a good choice to pass for the `hint` argument.
754
-
755
  *Returns:* A pointer to the initial element of an array of storage of
756
  size `n` `* sizeof(T)`, aligned appropriately for objects of type `T`.
757
- It is *implementation-defined* whether over-aligned types are
758
- supported ([[basic.align]]).
759
 
760
- the storage is obtained by calling
761
- `::operator new(std::size_t)` ([[new.delete]]), but it is unspecified
762
- when or how often this function is called. The use of `hint` is
763
- unspecified, but intended as an aid to locality if an implementation so
764
- desires.
765
 
766
  *Throws:* `bad_alloc` if the storage cannot be obtained.
767
 
768
  ``` cpp
769
- void deallocate(pointer p, size_type n);
770
  ```
771
 
772
  *Requires:* `p` shall be a pointer value obtained from `allocate()`. `n`
773
  shall equal the value passed as the first argument to the invocation of
774
  allocate which returned `p`.
775
 
776
  *Effects:* Deallocates the storage referenced by `p` .
777
 
778
- *Remarks:* Uses
779
- `::operator delete(void*, std::size_t)` ([[new.delete]]), but it is
780
  unspecified when this function is called.
781
 
782
- ``` cpp
783
- size_type max_size() const noexcept;
784
- ```
785
-
786
- *Returns:* The largest value *N* for which the call `allocate(N,0)`
787
- might succeed.
788
-
789
- ``` cpp
790
- template <class U, class... Args>
791
- void construct(U* p, Args&&... args);
792
- ```
793
-
794
- *Effects:* `::new((void *)p) U(std::forward<Args>(args)...)`
795
-
796
- ``` cpp
797
- template <class U>
798
- void destroy(U* p);
799
- ```
800
-
801
- *Effects:* `p->~U()`
802
-
803
  #### `allocator` globals <a id="allocator.globals">[[allocator.globals]]</a>
804
 
805
  ``` cpp
806
- template <class T1, class T2>
807
- bool operator==(const allocator<T1>&, const allocator<T2>&) noexcept;
808
  ```
809
 
810
  *Returns:* `true`.
811
 
812
  ``` cpp
813
- template <class T1, class T2>
814
- bool operator!=(const allocator<T1>&, const allocator<T2>&) noexcept;
815
  ```
816
 
817
  *Returns:* `false`.
818
 
819
- ### Raw storage iterator <a id="storage.iterator">[[storage.iterator]]</a>
820
-
821
- `raw_storage_iterator` is provided to enable algorithms to store their
822
- results into uninitialized memory. The template parameter
823
- `OutputIterator` is required to have its `operator*` return an object
824
- for which `operator&` is defined and returns a pointer to `T`, and is
825
- also required to satisfy the requirements of an output iterator (
826
- [[output.iterators]]).
827
-
828
- ``` cpp
829
- namespace std {
830
- template <class OutputIterator, class T>
831
- class raw_storage_iterator
832
- : public iterator<output_iterator_tag,void,void,void,void> {
833
- public:
834
- explicit raw_storage_iterator(OutputIterator x);
835
-
836
- raw_storage_iterator& operator*();
837
- raw_storage_iterator& operator=(const T& element);
838
- raw_storage_iterator& operator++();
839
- raw_storage_iterator operator++(int);
840
- };
841
- }
842
- ```
843
-
844
- ``` cpp
845
- explicit raw_storage_iterator(OutputIterator x);
846
- ```
847
-
848
- *Effects:* Initializes the iterator to point to the same value to which
849
- `x` points.
850
-
851
- ``` cpp
852
- raw_storage_iterator& operator*();
853
- ```
854
-
855
- *Returns:* `*this`
856
-
857
- ``` cpp
858
- raw_storage_iterator& operator=(const T& element);
859
- ```
860
-
861
- *Effects:* Constructs a value from `element` at the location to which
862
- the iterator points.
863
-
864
- *Returns:* A reference to the iterator.
865
-
866
- ``` cpp
867
- raw_storage_iterator& operator++();
868
- ```
869
-
870
- *Effects:* Pre-increment: advances the iterator and returns a reference
871
- to the updated iterator.
872
-
873
- ``` cpp
874
- raw_storage_iterator operator++(int);
875
- ```
876
-
877
- *Effects:* Post-increment: advances the iterator and returns the old
878
- value of the iterator.
879
-
880
- ### Temporary buffers <a id="temporary.buffer">[[temporary.buffer]]</a>
881
-
882
- ``` cpp
883
- template <class T>
884
- pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
885
- ```
886
-
887
- *Effects:* Obtains a pointer to storage sufficient to store up to `n`
888
- adjacent `T` objects. It is *implementation-defined* whether
889
- over-aligned types are supported ([[basic.align]]).
890
-
891
- *Returns:* A `pair` containing the buffer’s address and capacity (in the
892
- units of `sizeof(T)`), or a pair of 0 values if no storage can be
893
- obtained or if `n <= 0`.
894
-
895
- ``` cpp
896
- template <class T> void return_temporary_buffer(T* p);
897
- ```
898
-
899
- *Effects:* Deallocates the buffer to which `p` points.
900
-
901
- *Requires:* The buffer shall have been previously allocated by
902
- `get_temporary_buffer`.
903
-
904
  ### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
905
 
906
- All the iterators that are used as template parameters in the following
907
- algorithms are required to have their `operator*` return an object for
908
- which `operator&` is defined and returns a pointer to `T`. In the
909
- algorithm `uninitialized_copy`, the template parameter `InputIterator`
910
- is required to satisfy the requirements of an input iterator (
911
- [[input.iterators]]). In all of the following algorithms, the template
912
- parameter `ForwardIterator` is required to satisfy the requirements of a
913
- forward iterator ([[forward.iterators]]), and is required to have the
 
914
  property that no exceptions are thrown from increment, assignment,
915
- comparison, or indirection through valid iterators. In the following
916
- algorithms, if an exception is thrown there are no effects.
 
 
917
 
918
  #### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
919
 
920
  ``` cpp
921
- template <class T> T* addressof(T& r) noexcept;
922
  ```
923
 
924
  *Returns:* The actual address of the object or function referenced by
925
  `r`, even in the presence of an overloaded `operator&`.
926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
927
  #### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
928
 
929
  ``` cpp
930
  template <class InputIterator, class ForwardIterator>
931
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
932
  ForwardIterator result);
933
  ```
934
 
935
- *Effects:*
936
 
937
  ``` cpp
938
- for (; first != last; ++result, ++first)
939
- ::new (static_cast<void*>(&*result))
940
  typename iterator_traits<ForwardIterator>::value_type(*first);
941
  ```
942
 
943
- *Returns:* `result`
944
 
945
  ``` cpp
946
  template <class InputIterator, class Size, class ForwardIterator>
947
  ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
948
  ForwardIterator result);
949
  ```
950
 
951
- *Effects:*
952
 
953
  ``` cpp
954
- for ( ; n > 0; ++result, ++first, --n) {
955
- ::new (static_cast<void*>(&*result))
956
  typename iterator_traits<ForwardIterator>::value_type(*first);
957
  }
958
  ```
959
 
960
- *Returns:* `result`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
961
 
962
  #### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
963
 
964
  ``` cpp
965
  template <class ForwardIterator, class T>
966
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
967
  const T& x);
968
  ```
969
 
970
- *Effects:*
971
 
972
  ``` cpp
973
  for (; first != last; ++first)
974
- ::new (static_cast<void*>(&*first))
975
  typename iterator_traits<ForwardIterator>::value_type(x);
976
  ```
977
 
978
- #### `uninitialized_fill_n` <a id="uninitialized.fill.n">[[uninitialized.fill.n]]</a>
979
-
980
  ``` cpp
981
  template <class ForwardIterator, class Size, class T>
982
  ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
983
  ```
984
 
985
- *Effects:*
986
 
987
  ``` cpp
988
  for (; n--; ++first)
989
- ::new (static_cast<void*>(&*first))
990
  typename iterator_traits<ForwardIterator>::value_type(x);
991
  return first;
992
  ```
993
 
994
- ### C library <a id="c.malloc">[[c.malloc]]</a>
995
 
996
- Table  [[tab:util.hdr.cstdlib]] describes the header `<cstdlib>`.
 
 
 
997
 
998
- The contents are the same as the Standard C library header `<stdlib.h>,`
999
- with the following changes:
1000
 
1001
- The functions `calloc()`, `malloc()`, and `realloc()` do not attempt to
1002
- allocate storage by calling `::operator new()` ([[support.dynamic]]).
 
1003
 
1004
- The function `free()` does not attempt to deallocate storage by calling
1005
- `::operator delete()`.
 
 
1006
 
1007
- ISO C Clause 7.11.2.
1008
 
1009
- Storage allocated directly with `malloc()`, `calloc()`, or `realloc()`
1010
- is implicitly declared reachable (see  [[basic.stc.dynamic.safety]]) on
1011
- allocation, ceases to be declared reachable on deallocation, and need
1012
- not cease to be declared reachable as the result of an
1013
- `undeclare_reachable()` call. This allows existing C libraries to remain
1014
- unaffected by restrictions on pointers that are not safely derived, at
1015
- the expense of providing far fewer garbage collection and leak detection
1016
- options for `malloc()`-allocated objects. It also allows `malloc()` to
1017
- be implemented with a separate allocation arena, bypassing the normal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1018
  `declare_reachable()` implementation. The above functions should never
1019
  intentionally be used as a replacement for `declare_reachable()`, and
1020
  newly written code is strongly encouraged to treat memory allocated with
1021
- these functions as though it were allocated with `operator new`.
 
1022
 
1023
- Table  [[tab:util.hdr.cstring]] describes the header `<cstring>`.
 
 
1024
 
1025
- The contents are the same as the Standard C library header `<string.h>`,
1026
- with the change to `memchr()` specified in  [[c.strings]].
1027
 
1028
- ISO C Clause 7.11.2.
 
 
 
1029
 
 
1
  ## Memory <a id="memory">[[memory]]</a>
2
 
3
  ### In general <a id="memory.general">[[memory.general]]</a>
4
 
5
  This subclause describes the contents of the header `<memory>` (
6
+ [[memory.syn]]) and some of the contents of the header `<cstdlib>` (
7
+ [[cstdlib.syn]]).
8
 
9
  ### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
10
 
11
  The header `<memory>` defines several types and function templates that
12
  describe properties of pointers and pointer-like types, manage memory
13
+ for containers and other template types, destroy objects, and construct
14
+ multiple objects in uninitialized memory buffers ([[pointer.traits]]–
15
  [[specialized.algorithms]]). The header also defines the templates
16
  `unique_ptr`, `shared_ptr`, `weak_ptr`, and various function templates
17
  that operate on objects of these types ([[smartptr]]).
18
 
19
  ``` cpp
 
29
  void declare_no_pointers(char* p, size_t n);
30
  void undeclare_no_pointers(char* p, size_t n);
31
  pointer_safety get_pointer_safety() noexcept;
32
 
33
  // [ptr.align], pointer alignment function
34
+ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 
35
 
36
  // [allocator.tag], allocator argument tag
37
+ struct allocator_arg_t { explicit allocator_arg_t() = default; };
38
+ inline constexpr allocator_arg_t allocator_arg{};
39
 
40
  // [allocator.uses], uses_allocator
41
  template <class T, class Alloc> struct uses_allocator;
42
 
43
  // [allocator.traits], allocator traits
44
  template <class Alloc> struct allocator_traits;
45
 
46
+ // [default.allocator], the default allocator
47
  template <class T> class allocator;
 
48
  template <class T, class U>
49
  bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
50
  template <class T, class U>
51
  bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
52
 
53
+ // [specialized.algorithms], specialized algorithms
54
+ template <class T> constexpr T* addressof(T& r) noexcept;
55
+ template <class T> const T* addressof(const T&&) = delete;
56
+ template <class ForwardIterator>
57
+ void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
58
+ template <class ExecutionPolicy, class ForwardIterator>
59
+ void uninitialized_default_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
60
+ ForwardIterator first, ForwardIterator last);
61
+ template <class ForwardIterator, class Size>
62
+ ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
63
+ template <class ExecutionPolicy, class ForwardIterator, class Size>
64
+ ForwardIterator uninitialized_default_construct_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
65
+ ForwardIterator first, Size n);
66
+ template <class ForwardIterator>
67
+ void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
68
+ template <class ExecutionPolicy, class ForwardIterator>
69
+ void uninitialized_value_construct(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
70
+ ForwardIterator first, ForwardIterator last);
71
+ template <class ForwardIterator, class Size>
72
+ ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
73
+ template <class ExecutionPolicy, class ForwardIterator, class Size>
74
+ ForwardIterator uninitialized_value_construct_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
75
+ ForwardIterator first, Size n);
76
  template <class InputIterator, class ForwardIterator>
77
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
78
  ForwardIterator result);
79
+ template <class ExecutionPolicy, class InputIterator, class ForwardIterator>
80
+ ForwardIterator uninitialized_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
81
+ InputIterator first, InputIterator last,
82
+ ForwardIterator result);
83
  template <class InputIterator, class Size, class ForwardIterator>
84
  ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
85
  ForwardIterator result);
86
+ template <class ExecutionPolicy, class InputIterator, class Size, class ForwardIterator>
87
+ ForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
88
+ InputIterator first, Size n,
89
+ ForwardIterator result);
90
+ template <class InputIterator, class ForwardIterator>
91
+ ForwardIterator uninitialized_move(InputIterator first, InputIterator last,
92
+ ForwardIterator result);
93
+ template <class ExecutionPolicy, class InputIterator, class ForwardIterator>
94
+ ForwardIterator uninitialized_move(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
95
+ InputIterator first, InputIterator last,
96
+ ForwardIterator result);
97
+ template <class InputIterator, class Size, class ForwardIterator>
98
+ pair<InputIterator, ForwardIterator>
99
+ uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
100
+ template <class ExecutionPolicy, class InputIterator, class Size, class ForwardIterator>
101
+ pair<InputIterator, ForwardIterator>
102
+ uninitialized_move_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
103
+ InputIterator first, Size n, ForwardIterator result);
104
  template <class ForwardIterator, class T>
105
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
106
  const T& x);
107
+ template <class ExecutionPolicy, class ForwardIterator, class T>
108
+ void uninitialized_fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
109
+ ForwardIterator first, ForwardIterator last,
110
+ const T& x);
111
  template <class ForwardIterator, class Size, class T>
112
  ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
113
+ template <class ExecutionPolicy, class ForwardIterator, class Size, class T>
114
+ ForwardIterator uninitialized_fill_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
115
+ ForwardIterator first, Size n, const T& x);
116
+ template <class T>
117
+ void destroy_at(T* location);
118
+ template <class ForwardIterator>
119
+ void destroy(ForwardIterator first, ForwardIterator last);
120
+ template <class ExecutionPolicy, class ForwardIterator>
121
+ void destroy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
122
+ ForwardIterator first, ForwardIterator last);
123
+ template <class ForwardIterator, class Size>
124
+ ForwardIterator destroy_n(ForwardIterator first, Size n);
125
+ template <class ExecutionPolicy, class ForwardIterator, class Size>
126
+ ForwardIterator destroy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
127
+ ForwardIterator first, Size n);
128
 
129
+ // [unique.ptr], class template unique_ptr
130
  template <class T> struct default_delete;
131
  template <class T> struct default_delete<T[]>;
132
  template <class T, class D = default_delete<T>> class unique_ptr;
133
  template <class T, class D> class unique_ptr<T[], D>;
134
 
 
174
  template <class T, class D>
175
  bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
176
  template <class T, class D>
177
  bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
178
 
179
+ // [util.smartptr.weak.bad], class bad_weak_ptr
180
  class bad_weak_ptr;
181
 
182
+ // [util.smartptr.shared], class template shared_ptr
183
  template<class T> class shared_ptr;
184
 
185
  // [util.smartptr.shared.create], shared_ptr creation
186
+ template<class T, class... Args>
187
+ shared_ptr<T> make_shared(Args&&... args);
188
  template<class T, class A, class... Args>
189
  shared_ptr<T> allocate_shared(const A& a, Args&&... args);
190
 
191
+ // [util.smartptr.shared.cmp], shared_ptr comparisons
192
  template<class T, class U>
193
+ bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
194
  template<class T, class U>
195
+ bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
196
  template<class T, class U>
197
+ bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
198
  template<class T, class U>
199
+ bool operator>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
200
  template<class T, class U>
201
+ bool operator<=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
202
  template<class T, class U>
203
+ bool operator>=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
204
 
205
  template <class T>
206
  bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
207
  template <class T>
208
  bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
 
225
  template <class T>
226
  bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
227
  template <class T>
228
  bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
229
 
230
+ // [util.smartptr.shared.spec], shared_ptr specialized algorithms
231
+ template<class T>
232
+ void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
233
 
234
+ // [util.smartptr.shared.cast], shared_ptr casts
235
  template<class T, class U>
236
+ shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
237
  template<class T, class U>
238
+ shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
239
  template<class T, class U>
240
+ shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
241
 
242
+ // [util.smartptr.getdeleter], shared_ptr get_deleter
243
+ template<class D, class T>
244
+ D* get_deleter(const shared_ptr<T>& p) noexcept;
245
 
246
+ // [util.smartptr.shared.io], shared_ptr I/O
247
  template<class E, class T, class Y>
248
+ basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p);
249
 
250
+ // [util.smartptr.weak], class template weak_ptr
251
  template<class T> class weak_ptr;
252
 
253
+ // [util.smartptr.weak.spec], weak_ptr specialized algorithms
254
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
255
 
256
+ // [util.smartptr.ownerless], class template owner_less
257
+ template<class T = void> struct owner_less;
258
 
259
+ // [util.smartptr.enab], class template enable_shared_from_this
260
  template<class T> class enable_shared_from_this;
261
 
262
+ // [util.smartptr.shared.atomic], shared_ptr atomic access
263
  template<class T>
264
  bool atomic_is_lock_free(const shared_ptr<T>* p);
265
 
266
  template<class T>
267
  shared_ptr<T> atomic_load(const shared_ptr<T>* p);
 
274
  void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
275
 
276
  template<class T>
277
  shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
278
  template<class T>
279
+ shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
 
280
 
281
  template<class T>
282
  bool atomic_compare_exchange_weak(
283
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
284
  template<class T>
 
291
  template<class T>
292
  bool atomic_compare_exchange_strong_explicit(
293
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
294
  memory_order success, memory_order failure);
295
 
296
+ // [util.smartptr.hash], hash support
297
  template <class T> struct hash;
298
  template <class T, class D> struct hash<unique_ptr<T, D>>;
299
  template <class T> struct hash<shared_ptr<T>>;
300
 
301
+ // [allocator.uses.trait], uses_allocator
302
+ template <class T, class Alloc>
303
+ inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
304
  }
305
  ```
306
 
307
  ### Pointer traits <a id="pointer.traits">[[pointer.traits]]</a>
308
 
 
310
  certain attributes of pointer-like types.
311
 
312
  ``` cpp
313
  namespace std {
314
  template <class Ptr> struct pointer_traits {
315
+ using pointer = Ptr;
316
+ using element_type = see below;
317
+ using difference_type = see below;
318
 
319
  template <class U> using rebind = see below;
320
 
321
  static pointer pointer_to(see below r);
322
  };
323
 
324
  template <class T> struct pointer_traits<T*> {
325
+ using pointer = T*;
326
+ using element_type = T;
327
+ using difference_type = ptrdiff_t;
328
 
329
  template <class U> using rebind = U*;
330
 
331
  static pointer pointer_to(see below r) noexcept;
332
  };
 
334
  ```
335
 
336
  #### Pointer traits member types <a id="pointer.traits.types">[[pointer.traits.types]]</a>
337
 
338
  ``` cpp
339
+ using element_type = see below;
340
  ```
341
 
342
+ *Type:* `Ptr::element_type` if the *qualified-id* `Ptr::element_type` is
343
+ valid and denotes a type ([[temp.deduct]]); otherwise, `T` if `Ptr` is
344
+ a class template instantiation of the form `SomePointer<T, Args>`, where
345
+ `Args` is zero or more type arguments; otherwise, the specialization is
346
+ ill-formed.
347
 
348
  ``` cpp
349
+ using difference_type = see below;
350
  ```
351
 
352
+ *Type:* `Ptr::difference_type` if the *qualified-id*
353
+ `Ptr::difference_type` is valid and denotes a type ([[temp.deduct]]);
354
+ otherwise, `ptrdiff_t`.
355
 
356
  ``` cpp
357
  template <class U> using rebind = see below;
358
  ```
359
 
360
+ *Alias template:* `Ptr::rebind<U>` if the *qualified-id*
361
+ `Ptr::rebind<U>` is valid and denotes a type ([[temp.deduct]]);
362
+ otherwise, `SomePointer<U, Args>` if `Ptr` is a class template
363
+ instantiation of the form `SomePointer<T, Args>`, where `Args` is zero
364
+ or more type arguments; otherwise, the instantiation of `rebind` is
365
+ ill-formed.
366
 
367
  #### Pointer traits member functions <a id="pointer.traits.functions">[[pointer.traits.functions]]</a>
368
 
369
  ``` cpp
370
  static pointer pointer_traits::pointer_to(see below r);
371
  static pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
372
  ```
373
 
374
+ *Remarks:* If `element_type` is cv `void`, the type of `r` is
375
  unspecified; otherwise, it is `element_type&`.
376
 
377
  *Returns:* The first member function returns a pointer to `r` obtained
378
  by calling `Ptr::pointer_to(r)` through which indirection is valid; an
379
  instantiation of this function is ill-formed if `Ptr` does not have a
380
  matching `pointer_to` static member function. The second member function
381
+ returns `addressof(r)`.
382
 
383
  ### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
384
 
385
  A complete object is *declared reachable* while the number of calls to
386
  `declare_reachable` with an argument referencing the object exceeds the
 
395
  pointer ([[basic.stc.dynamic.safety]]) or a null pointer value.
396
 
397
  *Effects:* If `p` is not null, the complete object referenced by `p` is
398
  subsequently declared reachable ([[basic.stc.dynamic.safety]]).
399
 
400
+ *Throws:* May throw `bad_alloc` if the system cannot allocate additional
401
+ memory that may be required to track objects declared reachable.
 
402
 
403
  ``` cpp
404
  template <class T> T* undeclare_reachable(T* p);
405
  ```
406
 
 
412
  *Returns:* A safely derived copy of `p` which shall compare equal to
413
  `p`.
414
 
415
  *Throws:* Nothing.
416
 
417
+ [*Note 1*: It is expected that calls to `declare_reachable(p)` will
418
+ consume a small amount of memory in addition to that occupied by the
419
+ referenced object until the matching call to `undeclare_reachable(p)` is
420
+ encountered. Long running programs should arrange that calls are
421
+ matched. — *end note*]
422
 
423
  ``` cpp
424
  void declare_no_pointers(char* p, size_t n);
425
  ```
426
 
427
  *Requires:* No bytes in the specified range are currently registered
428
  with `declare_no_pointers()`. If the specified range is in an allocated
429
  object, then it must be entirely within a single allocated object. The
430
  object must be live until the corresponding `undeclare_no_pointers()`
431
+ call.
432
+
433
+ [*Note 2*: In a garbage-collecting implementation, the fact that a
434
+ region in an object is registered with `declare_no_pointers()` should
435
+ not prevent the object from being collected. — *end note*]
436
 
437
  *Effects:* The `n` bytes starting at `p` no longer contain traceable
438
  pointer locations, independent of their type. Hence indirection through
439
  a pointer located there is undefined if the object it points to was
440
  created by global `operator new` and not previously declared reachable.
441
+
442
+ [*Note 3*: This may be used to inform a garbage collector or leak
443
+ detector that this region of memory need not be traced. — *end note*]
444
 
445
  *Throws:* Nothing.
446
 
447
+ [*Note 4*: Under some conditions implementations may need to allocate
448
+ memory. However, the request can be ignored if memory allocation
449
+ fails. — *end note*]
450
 
451
  ``` cpp
452
  void undeclare_no_pointers(char* p, size_t n);
453
  ```
454
 
 
464
  ``` cpp
465
  pointer_safety get_pointer_safety() noexcept;
466
  ```
467
 
468
  *Returns:* `pointer_safety::strict` if the implementation has strict
469
+ pointer safety ([[basic.stc.dynamic.safety]]). It is
470
+ *implementation-defined* whether `get_pointer_safety` returns
471
+ `pointer_safety::relaxed` or `pointer_safety::preferred` if the
472
+ implementation has relaxed pointer safety.[^1]
473
 
474
  ### Align <a id="ptr.align">[[ptr.align]]</a>
475
 
476
  ``` cpp
477
+ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 
478
  ```
479
 
480
  *Effects:* If it is possible to fit `size` bytes of storage aligned by
481
  `alignment` into the buffer pointed to by `ptr` with length `space`, the
482
+ function updates `ptr` to represent the first possible address of such
483
  storage and decreases `space` by the number of bytes used for alignment.
484
  Otherwise, the function does nothing.
485
 
486
  *Requires:*
487
 
488
+ - `alignment` shall be a power of two
489
+ - `ptr` shall represent the address of contiguous storage of at least
490
+ `space` bytes
491
 
492
  *Returns:* A null pointer if the requested aligned buffer would not fit
493
  into the available space, otherwise the adjusted value of `ptr`.
494
 
495
+ [*Note 1*: The function updates its `ptr` and `space` arguments so that
496
+ it can be called repeatedly with possibly different `alignment` and
497
+ `size` arguments for the same buffer. — *end note*]
498
 
499
  ### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
500
 
501
  ``` cpp
502
  namespace std {
503
+ struct allocator_arg_t { explicit allocator_arg_t() = default; };
504
+ inline constexpr allocator_arg_t allocator_arg{};
505
  }
506
  ```
507
 
508
  The `allocator_arg_t` struct is an empty structure type used as a unique
509
  type to disambiguate constructor and function overloading. Specifically,
 
518
 
519
  ``` cpp
520
  template <class T, class Alloc> struct uses_allocator;
521
  ```
522
 
523
+ *Remarks:* Automatically detects whether `T` has a nested
524
+ `allocator_type` that is convertible from `Alloc`. Meets the
525
+ `BinaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
526
+ shall provide a definition that is derived from `true_type` if the
527
+ *qualified-id* `T::allocator_type` is valid and denotes a
528
+ type ([[temp.deduct]]) and
529
+ `is_convertible_v<Alloc, T::allocator_type> != false`, otherwise it
530
  shall be derived from `false_type`. A program may specialize this
531
  template to derive from `true_type` for a user-defined type `T` that
532
  does not have a nested `allocator_type` but nonetheless can be
533
  constructed with an allocator where either:
534
 
535
  - the first argument of a constructor has type `allocator_arg_t` and the
536
  second argument has type `Alloc` or
537
  - the last argument of a constructor has type `Alloc`.
538
 
539
+ #### Uses-allocator construction <a id="allocator.uses.construction">[[allocator.uses.construction]]</a>
540
 
541
  *Uses-allocator construction* with allocator `Alloc` refers to the
542
  construction of an object `obj` of type `T`, using constructor arguments
543
  `v1, v2, ..., vN` of types `V1, V2, ..., VN`, respectively, and an
544
  allocator `alloc` of type `Alloc`, according to the following rules:
545
 
546
+ - if `uses_allocator_v<T, Alloc>` is `false` and
547
+ `is_constructible_v<T, V1, V2, ..., VN>` is `true`, then `obj` is
548
  initialized as `obj(v1, v2, ..., vN)`;
549
+ - otherwise, if `uses_allocator_v<T, Alloc>` is `true` and
550
+ `is_constructible_v<T, allocator_arg_t, Alloc,` `V1, V2, ..., VN>` is
551
+ `true`, then `obj` is initialized as `obj(allocator_arg, alloc, v1,
 
552
  v2, ..., vN)`;
553
+ - otherwise, if `uses_allocator_v<T, Alloc>` is `true` and
554
+ `is_constructible_v<T, V1, V2, ..., VN, Alloc>` is `true`, then `obj`
555
+ is initialized as `obj(v1, v2, ..., vN, alloc)`;
556
  - otherwise, the request for uses-allocator construction is ill-formed.
557
+ \[*Note 1*: An error will result if `uses_allocator_v<T, Alloc>` is
558
+ `true` but the specific constructor does not take an allocator. This
559
  definition prevents a silent failure to pass the allocator to an
560
+ element. — *end note*]
561
 
562
  ### Allocator traits <a id="allocator.traits">[[allocator.traits]]</a>
563
 
564
  The class template `allocator_traits` supplies a uniform interface to
565
  all allocator types. An allocator cannot be a non-class type, however,
566
+ even if `allocator_traits` supplies the entire required interface.
567
+
568
+ [*Note 1*: Thus, it is always possible to create a derived class from
569
+ an allocator. — *end note*]
570
 
571
  ``` cpp
572
  namespace std {
573
  template <class Alloc> struct allocator_traits {
574
+ using allocator_type = Alloc;
575
 
576
+ using value_type = typename Alloc::value_type;
577
 
578
+ using pointer = see below;
579
+ using const_pointer = see below;
580
+ using void_pointer = see below;
581
+ using const_void_pointer = see below;
582
 
583
+ using difference_type = see below;
584
+ using size_type = see below;
585
 
586
+ using propagate_on_container_copy_assignment = see below;
587
+ using propagate_on_container_move_assignment = see below;
588
+ using propagate_on_container_swap = see below;
589
+ using is_always_equal = see below;
590
 
591
  template <class T> using rebind_alloc = see below;
592
  template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
593
 
594
  static pointer allocate(Alloc& a, size_type n);
 
610
  ```
611
 
612
  #### Allocator traits member types <a id="allocator.traits.types">[[allocator.traits.types]]</a>
613
 
614
  ``` cpp
615
+ using pointer = see below;
616
  ```
617
 
618
+ *Type:* `Alloc::pointer` if the *qualified-id* `Alloc::pointer` is valid
619
+ and denotes a type ([[temp.deduct]]); otherwise, `value_type*`.
620
 
621
  ``` cpp
622
+ using const_pointer = see below;
623
  ```
624
 
625
+ *Type:* `Alloc::const_pointer` if the *qualified-id*
626
+ `Alloc::const_pointer` is valid and denotes a type ([[temp.deduct]]);
627
+ otherwise, `pointer_traits<pointer>::rebind<const value_type>`.
628
 
629
  ``` cpp
630
+ using void_pointer = see below;
631
  ```
632
 
633
+ *Type:* `Alloc::void_pointer` if the *qualified-id*
634
+ `Alloc::void_pointer` is valid and denotes a type ([[temp.deduct]]);
635
+ otherwise, `pointer_traits<pointer>::rebind<void>`.
636
 
637
  ``` cpp
638
+ using const_void_pointer = see below;
639
  ```
640
 
641
+ *Type:* `Alloc::const_void_pointer` if the *qualified-id*
642
+ `Alloc::const_void_pointer` is valid and denotes a
643
+ type ([[temp.deduct]]); otherwise,
644
  `pointer_traits<pointer>::rebind<const void>`.
645
 
646
  ``` cpp
647
+ using difference_type = see below;
648
  ```
649
 
650
+ *Type:* `Alloc::difference_type` if the *qualified-id*
651
+ `Alloc::difference_type` is valid and denotes a type ([[temp.deduct]]);
652
+ otherwise, `pointer_traits<pointer>::difference_type`.
653
 
654
  ``` cpp
655
+ using size_type = see below;
656
  ```
657
 
658
+ *Type:* `Alloc::size_type` if the *qualified-id* `Alloc::size_type` is
659
+ valid and denotes a type ([[temp.deduct]]); otherwise,
660
  `make_unsigned_t<difference_type>`.
661
 
662
  ``` cpp
663
+ using propagate_on_container_copy_assignment = see below;
664
  ```
665
 
666
+ *Type:* `Alloc::propagate_on_container_copy_assignment` if the
667
+ *qualified-id* `Alloc::propagate_on_container_copy_assignment` is valid
668
+ and denotes a type ([[temp.deduct]]); otherwise `false_type`.
669
 
670
  ``` cpp
671
+ using propagate_on_container_move_assignment = see below;
672
  ```
673
 
674
+ *Type:* `Alloc::propagate_on_container_move_assignment` if the
675
+ *qualified-id* `Alloc::propagate_on_container_move_assignment` is valid
676
+ and denotes a type ([[temp.deduct]]); otherwise `false_type`.
677
 
678
  ``` cpp
679
+ using propagate_on_container_swap = see below;
680
  ```
681
 
682
+ *Type:* `Alloc::propagate_on_container_swap` if the *qualified-id*
683
+ `Alloc::propagate_on_container_swap` is valid and denotes a
684
+ type ([[temp.deduct]]); otherwise `false_type`.
685
+
686
+ ``` cpp
687
+ using is_always_equal = see below;
688
+ ```
689
+
690
+ *Type:* `Alloc::is_always_equal` if the *qualified-id*
691
+ `Alloc::is_always_equal` is valid and denotes a type ([[temp.deduct]]);
692
+ otherwise `is_empty<Alloc>::type`.
693
 
694
  ``` cpp
695
  template <class T> using rebind_alloc = see below;
696
  ```
697
 
698
+ *Alias template:* `Alloc::rebind<T>::other` if the *qualified-id*
699
+ `Alloc::rebind<T>::other` is valid and denotes a
700
+ type ([[temp.deduct]]); otherwise, `Alloc<T, Args>` if `Alloc` is a
701
+ class template instantiation of the form `Alloc<U, Args>`, where `Args`
702
+ is zero or more type arguments; otherwise, the instantiation of
703
+ `rebind_alloc` is ill-formed.
704
 
705
  #### Allocator traits static member functions <a id="allocator.traits.members">[[allocator.traits.members]]</a>
706
 
707
  ``` cpp
708
  static pointer allocate(Alloc& a, size_type n);
 
719
 
720
  ``` cpp
721
  static void deallocate(Alloc& a, pointer p, size_type n);
722
  ```
723
 
724
+ *Effects:* Calls `a.deallocate(p, n)`.
725
 
726
  *Throws:* Nothing.
727
 
728
  ``` cpp
729
  template <class T, class... Args>
730
  static void construct(Alloc& a, T* p, Args&&... args);
731
  ```
732
 
733
+ *Effects:* Calls `a.construct(p, std::forward<Args>(args)...)` if that
734
  call is well-formed; otherwise, invokes
735
  `::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)`.
736
 
737
  ``` cpp
738
  template <class T>
739
  static void destroy(Alloc& a, T* p);
740
  ```
741
 
742
+ *Effects:* Calls `a.destroy(p)` if that call is well-formed; otherwise,
743
  invokes `p->~T()`.
744
 
745
  ``` cpp
746
  static size_type max_size(const Alloc& a) noexcept;
747
  ```
748
 
749
  *Returns:* `a.max_size()` if that expression is well-formed; otherwise,
750
+ `numeric_limits<size_type>::max()/sizeof(value_type)`.
751
 
752
  ``` cpp
753
  static Alloc select_on_container_copy_construction(const Alloc& rhs);
754
  ```
755
 
756
  *Returns:* `rhs.select_on_container_copy_construction()` if that
757
  expression is well-formed; otherwise, `rhs`.
758
 
759
  ### The default allocator <a id="default.allocator">[[default.allocator]]</a>
760
 
761
+ All specializations of the default allocator satisfy the allocator
762
+ completeness requirements ([[allocator.requirements.completeness]]).
763
+
764
  ``` cpp
765
  namespace std {
 
 
 
 
 
 
 
 
 
 
 
 
766
  template <class T> class allocator {
767
  public:
768
+ using value_type = T;
769
+ using propagate_on_container_move_assignment = true_type;
770
+ using is_always_equal = true_type;
 
 
 
 
 
 
771
 
772
  allocator() noexcept;
773
  allocator(const allocator&) noexcept;
774
  template <class U> allocator(const allocator<U>&) noexcept;
775
  ~allocator();
776
 
777
+ T* allocate(size_t n);
778
+ void deallocate(T* p, size_t n);
 
 
 
 
 
 
 
 
 
 
779
  };
780
  }
781
  ```
782
 
783
  #### `allocator` members <a id="allocator.members">[[allocator.members]]</a>
 
788
  to these functions that allocate or deallocate a particular unit of
789
  storage shall occur in a single total order, and each such deallocation
790
  call shall happen before the next allocation (if any) in this order.
791
 
792
  ``` cpp
793
+ T* allocate(size_t n);
794
  ```
795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
796
  *Returns:* A pointer to the initial element of an array of storage of
797
  size `n` `* sizeof(T)`, aligned appropriately for objects of type `T`.
 
 
798
 
799
+ *Remarks:* the storage is obtained by calling
800
+ `::operator new` ([[new.delete]]), but it is unspecified when or how
801
+ often this function is called.
 
 
802
 
803
  *Throws:* `bad_alloc` if the storage cannot be obtained.
804
 
805
  ``` cpp
806
+ void deallocate(T* p, size_t n);
807
  ```
808
 
809
  *Requires:* `p` shall be a pointer value obtained from `allocate()`. `n`
810
  shall equal the value passed as the first argument to the invocation of
811
  allocate which returned `p`.
812
 
813
  *Effects:* Deallocates the storage referenced by `p` .
814
 
815
+ *Remarks:* Uses `::operator delete` ([[new.delete]]), but it is
 
816
  unspecified when this function is called.
817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
818
  #### `allocator` globals <a id="allocator.globals">[[allocator.globals]]</a>
819
 
820
  ``` cpp
821
+ template <class T, class U>
822
+ bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
823
  ```
824
 
825
  *Returns:* `true`.
826
 
827
  ``` cpp
828
+ template <class T, class U>
829
+ bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
830
  ```
831
 
832
  *Returns:* `false`.
833
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
834
  ### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
835
 
836
+ Throughout this subclause, the names of template parameters are used to
837
+ express type requirements.
838
+
839
+ - If an algorithm’s template parameter is named `InputIterator`, the
840
+ template argument shall satisfy the requirements of an input
841
+ iterator ([[input.iterators]]).
842
+ - If an algorithm’s template parameter is named `ForwardIterator`, the
843
+ template argument shall satisfy the requirements of a forward
844
+ iterator ([[forward.iterators]]), and is required to have the
845
  property that no exceptions are thrown from increment, assignment,
846
+ comparison, or indirection through valid iterators.
847
+
848
+ Unless otherwise specified, if an exception is thrown in the following
849
+ algorithms there are no effects.
850
 
851
  #### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
852
 
853
  ``` cpp
854
+ template <class T> constexpr T* addressof(T& r) noexcept;
855
  ```
856
 
857
  *Returns:* The actual address of the object or function referenced by
858
  `r`, even in the presence of an overloaded `operator&`.
859
 
860
+ *Remarks:* An expression `addressof(E)` is a constant
861
+ subexpression ([[defns.const.subexpr]]) if `E` is an lvalue constant
862
+ subexpression.
863
+
864
+ #### `uninitialized_default_construct` <a id="uninitialized.construct.default">[[uninitialized.construct.default]]</a>
865
+
866
+ ``` cpp
867
+ template <class ForwardIterator>
868
+ void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
869
+ ```
870
+
871
+ *Effects:* Equivalent to:
872
+
873
+ ``` cpp
874
+ for (; first != last; ++first)
875
+ ::new (static_cast<void*>(addressof(*first)))
876
+ typename iterator_traits<ForwardIterator>::value_type;
877
+ ```
878
+
879
+ ``` cpp
880
+ template <class ForwardIterator, class Size>
881
+ ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
882
+ ```
883
+
884
+ *Effects:* Equivalent to:
885
+
886
+ ``` cpp
887
+ for (; n>0; (void)++first, --n)
888
+ ::new (static_cast<void*>(addressof(*first)))
889
+ typename iterator_traits<ForwardIterator>::value_type;
890
+ return first;
891
+ ```
892
+
893
+ #### `uninitialized_value_construct` <a id="uninitialized.construct.value">[[uninitialized.construct.value]]</a>
894
+
895
+ ``` cpp
896
+ template <class ForwardIterator>
897
+ void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
898
+ ```
899
+
900
+ *Effects:* Equivalent to:
901
+
902
+ ``` cpp
903
+ for (; first != last; ++first)
904
+ ::new (static_cast<void*>(addressof(*first)))
905
+ typename iterator_traits<ForwardIterator>::value_type();
906
+ ```
907
+
908
+ ``` cpp
909
+ template <class ForwardIterator, class Size>
910
+ ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
911
+ ```
912
+
913
+ *Effects:* Equivalent to:
914
+
915
+ ``` cpp
916
+ for (; n>0; (void)++first, --n)
917
+ ::new (static_cast<void*>(addressof(*first)))
918
+ typename iterator_traits<ForwardIterator>::value_type();
919
+ return first;
920
+ ```
921
+
922
  #### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
923
 
924
  ``` cpp
925
  template <class InputIterator, class ForwardIterator>
926
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
927
  ForwardIterator result);
928
  ```
929
 
930
+ *Effects:* As if by:
931
 
932
  ``` cpp
933
+ for (; first != last; ++result, (void) ++first)
934
+ ::new (static_cast<void*>(addressof(*result)))
935
  typename iterator_traits<ForwardIterator>::value_type(*first);
936
  ```
937
 
938
+ *Returns:* `result`.
939
 
940
  ``` cpp
941
  template <class InputIterator, class Size, class ForwardIterator>
942
  ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
943
  ForwardIterator result);
944
  ```
945
 
946
+ *Effects:* As if by:
947
 
948
  ``` cpp
949
+ for ( ; n > 0; ++result, (void) ++first, --n) {
950
+ ::new (static_cast<void*>(addressof(*result)))
951
  typename iterator_traits<ForwardIterator>::value_type(*first);
952
  }
953
  ```
954
 
955
+ *Returns:* `result`.
956
+
957
+ #### `uninitialized_move` <a id="uninitialized.move">[[uninitialized.move]]</a>
958
+
959
+ ``` cpp
960
+ template <class InputIterator, class ForwardIterator>
961
+ ForwardIterator uninitialized_move(InputIterator first, InputIterator last,
962
+ ForwardIterator result);
963
+ ```
964
+
965
+ *Effects:* Equivalent to:
966
+
967
+ ``` cpp
968
+ for (; first != last; (void)++result, ++first)
969
+ ::new (static_cast<void*>(addressof(*result)))
970
+ typename iterator_traits<ForwardIterator>::value_type(std::move(*first));
971
+ return result;
972
+ ```
973
+
974
+ *Remarks:* If an exception is thrown, some objects in the range
975
+ \[`first`, `last`) are left in a valid but unspecified state.
976
+
977
+ ``` cpp
978
+ template <class InputIterator, class Size, class ForwardIterator>
979
+ pair<InputIterator, ForwardIterator>
980
+ uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
981
+ ```
982
+
983
+ *Effects:* Equivalent to:
984
+
985
+ ``` cpp
986
+ for (; n > 0; ++result, (void) ++first, --n)
987
+ ::new (static_cast<void*>(addressof(*result)))
988
+ typename iterator_traits<ForwardIterator>::value_type(std::move(*first));
989
+ return {first,result};
990
+ ```
991
+
992
+ *Remarks:* If an exception is thrown, some objects in the range
993
+ \[`first`, `std::next(first,n)`) are left in a valid but unspecified
994
+ state.
995
 
996
  #### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
997
 
998
  ``` cpp
999
  template <class ForwardIterator, class T>
1000
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
1001
  const T& x);
1002
  ```
1003
 
1004
+ *Effects:* As if by:
1005
 
1006
  ``` cpp
1007
  for (; first != last; ++first)
1008
+ ::new (static_cast<void*>(addressof(*first)))
1009
  typename iterator_traits<ForwardIterator>::value_type(x);
1010
  ```
1011
 
 
 
1012
  ``` cpp
1013
  template <class ForwardIterator, class Size, class T>
1014
  ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
1015
  ```
1016
 
1017
+ *Effects:* As if by:
1018
 
1019
  ``` cpp
1020
  for (; n--; ++first)
1021
+ ::new (static_cast<void*>(addressof(*first)))
1022
  typename iterator_traits<ForwardIterator>::value_type(x);
1023
  return first;
1024
  ```
1025
 
1026
+ #### `destroy` <a id="specialized.destroy">[[specialized.destroy]]</a>
1027
 
1028
+ ``` cpp
1029
+ template <class T>
1030
+ void destroy_at(T* location);
1031
+ ```
1032
 
1033
+ *Effects:* Equivalent to:
 
1034
 
1035
+ ``` cpp
1036
+ location->~T();
1037
+ ```
1038
 
1039
+ ``` cpp
1040
+ template <class ForwardIterator>
1041
+ void destroy(ForwardIterator first, ForwardIterator last);
1042
+ ```
1043
 
1044
+ *Effects:* Equivalent to:
1045
 
1046
+ ``` cpp
1047
+ for (; first!=last; ++first)
1048
+ destroy_at(addressof(*first));
1049
+ ```
1050
+
1051
+ ``` cpp
1052
+ template <class ForwardIterator, class Size>
1053
+ ForwardIterator destroy_n(ForwardIterator first, Size n);
1054
+ ```
1055
+
1056
+ *Effects:* Equivalent to:
1057
+
1058
+ ``` cpp
1059
+ for (; n > 0; (void)++first, --n)
1060
+ destroy_at(addressof(*first));
1061
+ return first;
1062
+ ```
1063
+
1064
+ ### C library memory allocation <a id="c.malloc">[[c.malloc]]</a>
1065
+
1066
+ [*Note 1*: The header `<cstdlib>` ([[cstdlib.syn]]) declares the
1067
+ functions described in this subclause. — *end note*]
1068
+
1069
+ ``` cpp
1070
+ void* aligned_alloc(size_t alignment, size_t size);
1071
+ void* calloc(size_t nmemb, size_t size);
1072
+ void* malloc(size_t size);
1073
+ void* realloc(void* ptr, size_t size);
1074
+ ```
1075
+
1076
+ *Effects:* These functions have the semantics specified in the C
1077
+ standard library.
1078
+
1079
+ *Remarks:* These functions do not attempt to allocate storage by calling
1080
+ `::operator new()` ([[support.dynamic]]).
1081
+
1082
+ Storage allocated directly with these functions is implicitly declared
1083
+ reachable (see  [[basic.stc.dynamic.safety]]) on allocation, ceases to
1084
+ be declared reachable on deallocation, and need not cease to be declared
1085
+ reachable as the result of an `undeclare_reachable()` call.
1086
+
1087
+ [*Note 1*: This allows existing C libraries to remain unaffected by
1088
+ restrictions on pointers that are not safely derived, at the expense of
1089
+ providing far fewer garbage collection and leak detection options for
1090
+ `malloc()`-allocated objects. It also allows `malloc()` to be
1091
+ implemented with a separate allocation arena, bypassing the normal
1092
  `declare_reachable()` implementation. The above functions should never
1093
  intentionally be used as a replacement for `declare_reachable()`, and
1094
  newly written code is strongly encouraged to treat memory allocated with
1095
+ these functions as though it were allocated with
1096
+ `operator new`. — *end note*]
1097
 
1098
+ ``` cpp
1099
+ void free(void* ptr);
1100
+ ```
1101
 
1102
+ *Effects:* This function has the semantics specified in the C standard
1103
+ library.
1104
 
1105
+ *Remarks:* This function does not attempt to deallocate storage by
1106
+ calling `::operator delete()`.
1107
+
1108
+ ISO C 7.22.3.
1109