From Jason Turner

[unique.ptr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpz4clb0ex/{from.md → to.md} +250 -298
tmp/tmpz4clb0ex/{from.md → to.md} RENAMED
@@ -2,105 +2,35 @@
2
 
3
  A *unique pointer* is an object that owns another object and manages
4
  that other object through a pointer. More precisely, a unique pointer is
5
  an object *u* that stores a pointer to a second object *p* and will
6
  dispose of *p* when *u* is itself destroyed (e.g., when leaving block
7
- scope ([[stmt.dcl]])). In this context, *u* is said to *own* `p`.
8
 
9
  The mechanism by which *u* disposes of *p* is known as *p*’s associated
10
  *deleter*, a function object whose correct invocation results in *p*’s
11
  appropriate disposition (typically its deletion).
12
 
13
  Let the notation *u.p* denote the pointer stored by *u*, and let *u.d*
14
  denote the associated deleter. Upon request, *u* can *reset* (replace)
15
- *u.p* and *u.d* with another pointer and deleter, but must properly
16
- dispose of its owned object via the associated deleter before such
17
- replacement is considered completed.
18
-
19
- Additionally, *u* can, upon request, *transfer ownership* to another
20
- unique pointer *u2*. Upon completion of such a transfer, the following
21
- postconditions hold:
22
-
23
- - *u2.p* is equal to the pre-transfer *u.p*,
24
- - *u.p* is equal to `nullptr`, and
25
- - if the pre-transfer *u.d* maintained state, such state has been
26
- transferred to *u2.d*.
27
-
28
- As in the case of a reset, *u2* must properly dispose of its
29
- pre-transfer owned object via the pre-transfer associated deleter before
30
- the ownership transfer is considered complete.
31
-
32
- [*Note 1*: A deleter’s state need never be copied, only moved or
33
- swapped as ownership is transferred. — *end note*]
34
 
35
  Each object of a type `U` instantiated from the `unique_ptr` template
36
  specified in this subclause has the strict ownership semantics,
37
  specified above, of a unique pointer. In partial satisfaction of these
38
- semantics, each such `U` is `MoveConstructible` and `MoveAssignable`,
39
- but is not `CopyConstructible` nor `CopyAssignable`. The template
40
- parameter `T` of `unique_ptr` may be an incomplete type.
 
41
 
42
- [*Note 2*: The uses of `unique_ptr` include providing exception safety
43
  for dynamically allocated memory, passing ownership of dynamically
44
  allocated memory to a function, and returning dynamically allocated
45
  memory from a function. — *end note*]
46
 
47
- ``` cpp
48
- namespace std {
49
- template<class T> struct default_delete;
50
- template<class T> struct default_delete<T[]>;
51
-
52
- template<class T, class D = default_delete<T>> class unique_ptr;
53
- template<class T, class D> class unique_ptr<T[], D>;
54
-
55
- template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
56
- template<class T> unique_ptr<T> make_unique(size_t n);
57
- template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
58
-
59
- template<class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
60
-
61
- template<class T1, class D1, class T2, class D2>
62
- bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
63
- template<class T1, class D1, class T2, class D2>
64
- bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
65
- template<class T1, class D1, class T2, class D2>
66
- bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
67
- template<class T1, class D1, class T2, class D2>
68
- bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
69
- template<class T1, class D1, class T2, class D2>
70
- bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
71
- template<class T1, class D1, class T2, class D2>
72
- bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
73
-
74
- template <class T, class D>
75
- bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
76
- template <class T, class D>
77
- bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
78
- template <class T, class D>
79
- bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
80
- template <class T, class D>
81
- bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
82
- template <class T, class D>
83
- bool operator<(const unique_ptr<T, D>& x, nullptr_t);
84
- template <class T, class D>
85
- bool operator<(nullptr_t, const unique_ptr<T, D>& y);
86
- template <class T, class D>
87
- bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
88
- template <class T, class D>
89
- bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
90
- template <class T, class D>
91
- bool operator>(const unique_ptr<T, D>& x, nullptr_t);
92
- template <class T, class D>
93
- bool operator>(nullptr_t, const unique_ptr<T, D>& y);
94
- template <class T, class D>
95
- bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
96
- template <class T, class D>
97
- bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
98
-
99
- }
100
- ```
101
-
102
  #### Default deleters <a id="unique.ptr.dltr">[[unique.ptr.dltr]]</a>
103
 
104
  ##### In general <a id="unique.ptr.dltr.general">[[unique.ptr.dltr.general]]</a>
105
 
106
  The class template `default_delete` serves as the default deleter
@@ -123,24 +53,23 @@ namespace std {
123
 
124
  ``` cpp
125
  template<class U> default_delete(const default_delete<U>& other) noexcept;
126
  ```
127
 
 
 
128
  *Effects:* Constructs a `default_delete` object from another
129
  `default_delete<U>` object.
130
 
131
- *Remarks:* This constructor shall not participate in overload resolution
132
- unless `U*` is implicitly convertible to `T*`.
133
-
134
  ``` cpp
135
  void operator()(T* ptr) const;
136
  ```
137
 
 
 
138
  *Effects:* Calls `delete` on `ptr`.
139
 
140
- *Remarks:* If `T` is an incomplete type, the program is ill-formed.
141
-
142
  ##### `default_delete<T[]>` <a id="unique.ptr.dltr.dflt1">[[unique.ptr.dltr.dflt1]]</a>
143
 
144
  ``` cpp
145
  namespace std {
146
  template<class T> struct default_delete<T[]> {
@@ -153,26 +82,25 @@ namespace std {
153
 
154
  ``` cpp
155
  template<class U> default_delete(const default_delete<U[]>& other) noexcept;
156
  ```
157
 
158
- *Effects:* constructs a `default_delete` object from another
 
 
159
  `default_delete<U[]>` object.
160
 
161
- *Remarks:* This constructor shall not participate in overload resolution
162
- unless `U(*)[]` is convertible to `T(*)[]`.
163
-
164
  ``` cpp
165
  template<class U> void operator()(U* ptr) const;
166
  ```
167
 
 
 
 
 
168
  *Effects:* Calls `delete[]` on `ptr`.
169
 
170
- *Remarks:* If `U` is an incomplete type, the program is ill-formed. This
171
- function shall not participate in overload resolution unless `U(*)[]` is
172
- convertible to `T(*)[]`.
173
-
174
  #### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
175
 
176
  ``` cpp
177
  namespace std {
178
  template<class T, class D = default_delete<T>> class unique_ptr {
@@ -194,11 +122,12 @@ namespace std {
194
  // [unique.ptr.single.dtor], destructor
195
  ~unique_ptr();
196
 
197
  // [unique.ptr.single.asgn], assignment
198
  unique_ptr& operator=(unique_ptr&& u) noexcept;
199
- template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
 
200
  unique_ptr& operator=(nullptr_t) noexcept;
201
 
202
  // [unique.ptr.single.observers], observers
203
  add_lvalue_reference_t<T> operator*() const;
204
  pointer operator->() const noexcept;
@@ -218,126 +147,107 @@ namespace std {
218
  };
219
  }
220
  ```
221
 
222
  The default type for the template parameter `D` is `default_delete`. A
223
- client-supplied template argument `D` shall be a function object type (
224
- [[function.objects]]), lvalue reference to function, or lvalue reference
225
  to function object type for which, given a value `d` of type `D` and a
226
  value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
227
  is valid and has the effect of disposing of the pointer as appropriate
228
  for that deleter.
229
 
230
- If the deleter’s type `D` is not a reference type, `D` shall satisfy the
231
- requirements of `Destructible` (Table  [[tab:destructible]]).
232
 
233
  If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
234
- denotes a type ([[temp.deduct]]), then `unique_ptr<T,
235
  D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
236
  Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
237
  `element_type*`. The type `unique_ptr<T,
238
- D>::pointer` shall satisfy the requirements of `NullablePointer` (
239
- [[nullablepointer.requirements]]).
240
 
241
- [*Example 1*: Given an allocator type `X` ([[allocator.requirements]])
242
- and letting `A` be a synonym for `allocator_traits<X>`, the types
243
  `A::pointer`, `A::const_pointer`, `A::void_pointer`, and
244
  `A::const_void_pointer` may be used as
245
  `unique_ptr<T, D>::pointer`. — *end example*]
246
 
247
- ##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
248
 
249
  ``` cpp
250
  constexpr unique_ptr() noexcept;
251
  constexpr unique_ptr(nullptr_t) noexcept;
252
  ```
253
 
254
- *Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
255
- (Table  [[tab:defaultconstructible]]), and that construction shall not
256
- throw an exception.
 
 
 
257
 
258
  *Effects:* Constructs a `unique_ptr` object that owns nothing,
259
  value-initializing the stored pointer and the stored deleter.
260
 
261
- *Postconditions:* `get() == nullptr`. `get_deleter()` returns a
262
- reference to the stored deleter.
263
-
264
- *Remarks:* If `is_pointer_v<deleter_type>` is `true` or
265
- `is_default_constructible_v<deleter_type>` is `false`, this constructor
266
- shall not participate in overload resolution.
267
 
268
  ``` cpp
269
  explicit unique_ptr(pointer p) noexcept;
270
  ```
271
 
272
- *Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
273
- (Table  [[tab:defaultconstructible]]), and that construction shall not
274
- throw an exception.
 
 
 
 
 
 
275
 
276
  *Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
277
  stored pointer with `p` and value-initializing the stored deleter.
278
 
279
- *Postconditions:* `get() == p`. `get_deleter()` returns a reference to
280
- the stored deleter.
281
-
282
- *Remarks:* If `is_pointer_v<deleter_type>` is `true` or
283
- `is_default_constructible_v<deleter_type>` is `false`, this constructor
284
- shall not participate in overload resolution. If class template argument
285
- deduction ([[over.match.class.deduct]]) would select the function
286
- template corresponding to this constructor, then the program is
287
- ill-formed.
288
-
289
- ``` cpp
290
- unique_ptr(pointer p, see below d1) noexcept;
291
- unique_ptr(pointer p, see below d2) noexcept;
292
- ```
293
-
294
- The signature of these constructors depends upon whether `D` is a
295
- reference type. If `D` is a non-reference type `A`, then the signatures
296
- are:
297
 
298
  ``` cpp
299
- unique_ptr(pointer p, const A& d) noexcept;
300
- unique_ptr(pointer p, A&& d) noexcept;
301
  ```
302
 
303
- If `D` is an lvalue reference type `A&`, then the signatures are:
304
 
305
- ``` cpp
306
- unique_ptr(pointer p, A& d) noexcept;
307
- unique_ptr(pointer p, A&& d) = delete;
308
- ```
309
-
310
- If `D` is an lvalue reference type `const A&`, then the signatures are:
311
 
312
- ``` cpp
313
- unique_ptr(pointer p, const A& d) noexcept;
314
- unique_ptr(pointer p, const A&& d) = delete;
315
- ```
 
316
 
317
  *Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
318
  the stored pointer with `p` and initializing the deleter from
319
  `std::forward<decltype(d)>(d)`.
320
 
321
- *Remarks:* These constructors shall not participate in overload
322
- resolution unless `is_constructible_v<D, decltype(d)>` is `true`.
 
323
 
324
- *Postconditions:* `get() == p`. `get_deleter()` returns a reference to
325
- the stored deleter. If `D` is a reference type then `get_deleter()`
326
- returns a reference to the lvalue `d`.
327
-
328
- *Remarks:* If class template argument
329
- deduction ([[over.match.class.deduct]]) would select a function
330
- template corresponding to either of these constructors, then the program
331
- is ill-formed.
332
 
333
  [*Example 1*:
334
 
335
  ``` cpp
336
  D d;
337
- unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
338
- unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
339
  unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
340
  unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
341
  // with reference deleter type
342
  ```
343
 
@@ -345,142 +255,144 @@ unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object comb
345
 
346
  ``` cpp
347
  unique_ptr(unique_ptr&& u) noexcept;
348
  ```
349
 
350
- *Requires:* If `D` is not a reference type, `D` shall satisfy the
351
- requirements of `MoveConstructible` (Table  [[tab:moveconstructible]]).
352
- Construction of the deleter from an rvalue of type `D` shall not throw
353
- an exception.
354
 
355
- *Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
356
- to `*this`. If `D` is a reference type, this deleter is copy constructed
357
- from `u`’s deleter; otherwise, this deleter is move constructed from
358
- `u`’s deleter.
359
 
360
- [*Note 1*: The deleter constructor can be implemented with
 
 
 
 
361
  `std::forward<D>`. — *end note*]
362
 
363
- *Postconditions:* `get()` yields the value `u.get()` yielded before the
364
- construction. `get_deleter()` returns a reference to the stored deleter
365
- that was constructed from `u.get_deleter()`. If `D` is a reference type
366
- then `get_deleter()` and `u.get_deleter()` both reference the same
367
- lvalue deleter.
368
 
369
  ``` cpp
370
  template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
371
  ```
372
 
373
- *Requires:* If `E` is not a reference type, construction of the deleter
374
- from an rvalue of type `E` shall be well formed and shall not throw an
 
 
 
 
 
 
 
375
  exception. Otherwise, `E` is a reference type and construction of the
376
- deleter from an lvalue of type `E` shall be well formed and shall not
377
- throw an exception.
378
 
379
- *Remarks:* This constructor shall not participate in overload resolution
380
- unless:
381
-
382
- - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
383
- - `U` is not an array type, and
384
- - either `D` is a reference type and `E` is the same type as `D`, or `D`
385
- is not a reference type and `E` is implicitly convertible to `D`.
386
-
387
- *Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
388
- to `*this`. If `E` is a reference type, this deleter is copy constructed
389
- from `u`’s deleter; otherwise, this deleter is move constructed from
390
- `u`’s deleter.
391
 
392
  [*Note 2*: The deleter constructor can be implemented with
393
  `std::forward<E>`. — *end note*]
394
 
395
- *Postconditions:* `get()` yields the value `u.get()` yielded before the
396
- construction. `get_deleter()` returns a reference to the stored deleter
397
- that was constructed from `u.get_deleter()`.
398
 
399
- ##### `unique_ptr` destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
400
 
401
  ``` cpp
402
  ~unique_ptr();
403
  ```
404
 
405
- *Requires:* The expression `get_deleter()(get())` shall be well formed,
406
- shall have well-defined behavior, and shall not throw exceptions.
407
 
408
  [*Note 3*: The use of `default_delete` requires `T` to be a complete
409
  type. — *end note*]
410
 
411
  *Effects:* If `get() == nullptr` there are no effects. Otherwise
412
  `get_deleter()(get())`.
413
 
414
- ##### `unique_ptr` assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
415
 
416
  ``` cpp
417
  unique_ptr& operator=(unique_ptr&& u) noexcept;
418
  ```
419
 
420
- *Requires:* If `D` is not a reference type, `D` shall satisfy the
421
- requirements of `MoveAssignable` (Table  [[tab:moveassignable]]) and
422
- assignment of the deleter from an rvalue of type `D` shall not throw an
 
 
423
  exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
424
- shall satisfy the `CopyAssignable` requirements and assignment of the
425
- deleter from an lvalue of type `D` shall not throw an exception.
426
 
427
- *Effects:* Transfers ownership from `u` to `*this` as if by calling
428
- `reset(u.release())` followed by
429
  `get_deleter() = std::forward<D>(u.get_deleter())`.
430
 
431
  *Returns:* `*this`.
432
 
 
 
433
  ``` cpp
434
  template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
435
  ```
436
 
437
- *Requires:* If `E` is not a reference type, assignment of the deleter
438
- from an rvalue of type `E` shall be well-formed and shall not throw an
439
- exception. Otherwise, `E` is a reference type and assignment of the
440
- deleter from an lvalue of type `E` shall be well-formed and shall not
441
- throw an exception.
442
-
443
- *Remarks:* This operator shall not participate in overload resolution
444
- unless:
445
 
446
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
447
  and
448
  - `U` is not an array type, and
449
  - `is_assignable_v<D&, E&&>` is `true`.
450
 
451
- *Effects:* Transfers ownership from `u` to `*this` as if by calling
452
- `reset(u.release())` followed by
 
 
 
 
 
453
  `get_deleter() = std::forward<E>(u.get_deleter())`.
454
 
455
  *Returns:* `*this`.
456
 
 
 
457
  ``` cpp
458
  unique_ptr& operator=(nullptr_t) noexcept;
459
  ```
460
 
461
  *Effects:* As if by `reset()`.
462
 
463
- *Postconditions:* `get() == nullptr`.
464
 
465
  *Returns:* `*this`.
466
 
467
- ##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
468
 
469
  ``` cpp
470
  add_lvalue_reference_t<T> operator*() const;
471
  ```
472
 
473
- *Requires:* `get() != nullptr`.
474
 
475
  *Returns:* `*get()`.
476
 
477
  ``` cpp
478
  pointer operator->() const noexcept;
479
  ```
480
 
481
- *Requires:* `get() != nullptr`.
482
 
483
  *Returns:* `get()`.
484
 
485
  [*Note 4*: The use of this function typically requires that `T` be a
486
  complete type. — *end note*]
@@ -502,47 +414,46 @@ const deleter_type& get_deleter() const noexcept;
502
  explicit operator bool() const noexcept;
503
  ```
504
 
505
  *Returns:* `get() != nullptr`.
506
 
507
- ##### `unique_ptr` modifiers <a id="unique.ptr.single.modifiers">[[unique.ptr.single.modifiers]]</a>
508
 
509
  ``` cpp
510
  pointer release() noexcept;
511
  ```
512
 
513
- *Postconditions:* `get() == nullptr`.
514
 
515
  *Returns:* The value `get()` had at the start of the call to `release`.
516
 
517
  ``` cpp
518
  void reset(pointer p = pointer()) noexcept;
519
  ```
520
 
521
- *Requires:* The expression `get_deleter()(get())` shall be well formed,
522
- shall have well-defined behavior, and shall not throw exceptions.
523
 
524
  *Effects:* Assigns `p` to the stored pointer, and then if and only if
525
  the old value of the stored pointer, `old_p`, was not equal to
526
  `nullptr`, calls `get_deleter()(old_p)`.
527
 
528
  [*Note 5*: The order of these operations is significant because the
529
  call to `get_deleter()` may destroy `*this`. — *end note*]
530
 
531
- *Postconditions:* `get() == p`.
532
 
533
  [*Note 6*: The postcondition does not hold if the call to
534
  `get_deleter()` destroys `*this` since `this->get()` is no longer a
535
  valid expression. — *end note*]
536
 
537
  ``` cpp
538
  void swap(unique_ptr& u) noexcept;
539
  ```
540
 
541
- *Requires:* `get_deleter()` shall be
542
- swappable ([[swappable.requirements]]) and shall not throw an exception
543
- under `swap`.
544
 
545
  *Effects:* Invokes `swap` on the stored pointers and on the stored
546
  deleters of `*this` and `u`.
547
 
548
  #### `unique_ptr` for array objects with a runtime length <a id="unique.ptr.runtime">[[unique.ptr.runtime]]</a>
@@ -610,19 +521,20 @@ interface.
610
  Descriptions are provided below only for members that differ from the
611
  primary template.
612
 
613
  The template argument `T` shall be a complete type.
614
 
615
- ##### `unique_ptr` constructors <a id="unique.ptr.runtime.ctor">[[unique.ptr.runtime.ctor]]</a>
616
 
617
  ``` cpp
618
  template<class U> explicit unique_ptr(U p) noexcept;
619
  ```
620
 
621
  This constructor behaves the same as the constructor in the primary
622
- template that takes a single parameter of type `pointer` except that it
623
- additionally shall not participate in overload resolution unless
 
624
 
625
  - `U` is the same type as `pointer`, or
626
  - `pointer` is the same type as `element_type*`, `U` is a pointer type
627
  `V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
628
 
@@ -630,70 +542,68 @@ additionally shall not participate in overload resolution unless
630
  template<class U> unique_ptr(U p, see below d) noexcept;
631
  template<class U> unique_ptr(U p, see below d) noexcept;
632
  ```
633
 
634
  These constructors behave the same as the constructors in the primary
635
- template that take a parameter of type `pointer` and a second parameter
636
- except that they shall not participate in overload resolution unless
637
- either
638
 
639
  - `U` is the same type as `pointer`,
640
  - `U` is `nullptr_t`, or
641
  - `pointer` is the same type as `element_type*`, `U` is a pointer type
642
  `V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
643
 
644
  ``` cpp
645
- template <class U, class E>
646
- unique_ptr(unique_ptr<U, E>&& u) noexcept;
647
  ```
648
 
649
- This constructor behaves the same as in the primary template, except
650
- that it shall not participate in overload resolution unless all of the
651
- following conditions hold, where `UP` is `unique_ptr<U, E>`:
652
 
653
  - `U` is an array type, and
654
  - `pointer` is the same type as `element_type*`, and
655
  - `UP::pointer` is the same type as `UP::element_type*`, and
656
  - `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
657
  - either `D` is a reference type and `E` is the same type as `D`, or `D`
658
  is not a reference type and `E` is implicitly convertible to `D`.
659
 
660
- [*Note 1*: This replaces the overload-resolution specification of the
661
- primary template — *end note*]
662
 
663
- ##### `unique_ptr` assignment <a id="unique.ptr.runtime.asgn">[[unique.ptr.runtime.asgn]]</a>
664
 
665
  ``` cpp
666
- template <class U, class E>
667
- unique_ptr& operator=(unique_ptr<U, E>&& u)noexcept;
668
  ```
669
 
670
- This operator behaves the same as in the primary template, except that
671
- it shall not participate in overload resolution unless all of the
672
- following conditions hold, where `UP` is `unique_ptr<U, E>`:
673
 
674
  - `U` is an array type, and
675
  - `pointer` is the same type as `element_type*`, and
676
  - `UP::pointer` is the same type as `UP::element_type*`, and
677
  - `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
678
  - `is_assignable_v<D&, E&&>` is `true`.
679
 
680
- [*Note 2*: This replaces the overload-resolution specification of the
681
- primary template — *end note*]
682
 
683
- ##### `unique_ptr` observers <a id="unique.ptr.runtime.observers">[[unique.ptr.runtime.observers]]</a>
684
 
685
  ``` cpp
686
  T& operator[](size_t i) const;
687
  ```
688
 
689
- *Requires:* `i <` the number of elements in the array to which the
690
  stored pointer points.
691
 
692
  *Returns:* `get()[i]`.
693
 
694
- ##### `unique_ptr` modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
695
 
696
  ``` cpp
697
  void reset(nullptr_t p = nullptr) noexcept;
698
  ```
699
 
@@ -702,145 +612,165 @@ void reset(nullptr_t p = nullptr) noexcept;
702
  ``` cpp
703
  template<class U> void reset(U p) noexcept;
704
  ```
705
 
706
  This function behaves the same as the `reset` member of the primary
707
- template, except that it shall not participate in overload resolution
708
- unless either
 
709
 
710
  - `U` is the same type as `pointer`, or
711
  - `pointer` is the same type as `element_type*`, `U` is a pointer type
712
  `V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
713
 
714
- #### `unique_ptr` creation <a id="unique.ptr.create">[[unique.ptr.create]]</a>
715
 
716
  ``` cpp
717
  template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
718
  ```
719
 
720
- *Remarks:* This function shall not participate in overload resolution
721
- unless `T` is not an array.
722
 
723
  *Returns:* `unique_ptr<T>(new T(std::forward<Args>(args)...))`.
724
 
725
  ``` cpp
726
  template<class T> unique_ptr<T> make_unique(size_t n);
727
  ```
728
 
729
- *Remarks:* This function shall not participate in overload resolution
730
- unless `T` is an array of unknown bound.
731
 
732
  *Returns:* `unique_ptr<T>(new remove_extent_t<T>[n]())`.
733
 
734
  ``` cpp
735
  template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
736
  ```
737
 
738
- *Remarks:* This function shall not participate in overload resolution
739
- unless `T` is an array of known bound.
740
 
741
- #### `unique_ptr` specialized algorithms <a id="unique.ptr.special">[[unique.ptr.special]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
 
743
  ``` cpp
744
  template<class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
745
  ```
746
 
747
- *Remarks:* This function shall not participate in overload resolution
748
- unless `is_swappable_v<D>` is `true`.
749
 
750
  *Effects:* Calls `x.swap(y)`.
751
 
752
  ``` cpp
753
  template<class T1, class D1, class T2, class D2>
754
  bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
755
  ```
756
 
757
  *Returns:* `x.get() == y.get()`.
758
 
759
- ``` cpp
760
- template <class T1, class D1, class T2, class D2>
761
- bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
762
- ```
763
-
764
- *Returns:* `x.get() != y.get()`.
765
-
766
  ``` cpp
767
  template<class T1, class D1, class T2, class D2>
768
  bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
769
  ```
770
 
771
- *Requires:* Let *`CT`* denote
772
 
773
  ``` cpp
774
  common_type_t<typename unique_ptr<T1, D1>::pointer,
775
  typename unique_ptr<T2, D2>::pointer>
776
  ```
777
 
778
- Then the specialization `less<`*`CT`*`>` shall be a function object
779
- type ([[function.objects]]) that induces a strict weak
780
- ordering ([[alg.sorting]]) on the pointer values.
781
 
782
- *Returns:* `less<`*`CT`*`>()(x.get(), y.get())`.
 
783
 
784
- *Remarks:* If `unique_ptr<T1, D1>::pointer` is not implicitly
785
- convertible to *`CT`* or `unique_ptr<T2, D2>::pointer` is not implicitly
786
- convertible to *`CT`*, the program is ill-formed.
787
 
788
- ``` cpp
789
- template <class T1, class D1, class T2, class D2>
790
- bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
791
- ```
792
-
793
- *Returns:* `!(y < x)`.
794
 
795
  ``` cpp
796
  template<class T1, class D1, class T2, class D2>
797
  bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
798
  ```
799
 
800
  *Returns:* `y < x`.
801
 
 
 
 
 
 
 
 
802
  ``` cpp
803
  template<class T1, class D1, class T2, class D2>
804
  bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
805
  ```
806
 
807
  *Returns:* `!(x < y)`.
808
 
 
 
 
 
 
 
 
 
 
 
 
809
  ``` cpp
810
  template<class T, class D>
811
  bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
812
- template <class T, class D>
813
- bool operator==(nullptr_t, const unique_ptr<T, D>& x) noexcept;
814
  ```
815
 
816
  *Returns:* `!x`.
817
 
818
- ``` cpp
819
- template <class T, class D>
820
- bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
821
- template <class T, class D>
822
- bool operator!=(nullptr_t, const unique_ptr<T, D>& x) noexcept;
823
- ```
824
-
825
- *Returns:* `(bool)x`.
826
-
827
  ``` cpp
828
  template<class T, class D>
829
  bool operator<(const unique_ptr<T, D>& x, nullptr_t);
830
  template<class T, class D>
831
  bool operator<(nullptr_t, const unique_ptr<T, D>& x);
832
  ```
833
 
834
- *Requires:* The specialization `less<unique_ptr<T, D>::pointer>` shall
835
- be a function object type ([[function.objects]]) that induces a strict
836
- weak ordering ([[alg.sorting]]) on the pointer values.
837
 
838
  *Returns:* The first function template returns
839
- `less<unique_ptr<T, D>::pointer>()(x.get(),`
840
- `nullptr)`. The second function template returns
841
- `less<unique_ptr<T, D>::pointer>()(nullptr, x.get())`.
 
 
 
 
 
 
 
842
 
843
  ``` cpp
844
  template<class T, class D>
845
  bool operator>(const unique_ptr<T, D>& x, nullptr_t);
846
  template<class T, class D>
@@ -868,5 +798,27 @@ template <class T, class D>
868
  ```
869
 
870
  *Returns:* The first function template returns `!(x < nullptr)`. The
871
  second function template returns `!(nullptr < x)`.
872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  A *unique pointer* is an object that owns another object and manages
4
  that other object through a pointer. More precisely, a unique pointer is
5
  an object *u* that stores a pointer to a second object *p* and will
6
  dispose of *p* when *u* is itself destroyed (e.g., when leaving block
7
+ scope [[stmt.dcl]]). In this context, *u* is said to *own* `p`.
8
 
9
  The mechanism by which *u* disposes of *p* is known as *p*’s associated
10
  *deleter*, a function object whose correct invocation results in *p*’s
11
  appropriate disposition (typically its deletion).
12
 
13
  Let the notation *u.p* denote the pointer stored by *u*, and let *u.d*
14
  denote the associated deleter. Upon request, *u* can *reset* (replace)
15
+ *u.p* and *u.d* with another pointer and deleter, but properly disposes
16
+ of its owned object via the associated deleter before such replacement
17
+ is considered completed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  Each object of a type `U` instantiated from the `unique_ptr` template
20
  specified in this subclause has the strict ownership semantics,
21
  specified above, of a unique pointer. In partial satisfaction of these
22
+ semantics, each such `U` is *Cpp17MoveConstructible* and
23
+ *Cpp17MoveAssignable*, but is not *Cpp17CopyConstructible* nor
24
+ *Cpp17CopyAssignable*. The template parameter `T` of `unique_ptr` may be
25
+ an incomplete type.
26
 
27
+ [*Note 1*: The uses of `unique_ptr` include providing exception safety
28
  for dynamically allocated memory, passing ownership of dynamically
29
  allocated memory to a function, and returning dynamically allocated
30
  memory from a function. — *end note*]
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  #### Default deleters <a id="unique.ptr.dltr">[[unique.ptr.dltr]]</a>
33
 
34
  ##### In general <a id="unique.ptr.dltr.general">[[unique.ptr.dltr.general]]</a>
35
 
36
  The class template `default_delete` serves as the default deleter
 
53
 
54
  ``` cpp
55
  template<class U> default_delete(const default_delete<U>& other) noexcept;
56
  ```
57
 
58
+ *Constraints:* `U*` is implicitly convertible to `T*`.
59
+
60
  *Effects:* Constructs a `default_delete` object from another
61
  `default_delete<U>` object.
62
 
 
 
 
63
  ``` cpp
64
  void operator()(T* ptr) const;
65
  ```
66
 
67
+ *Mandates:* `T` is a complete type.
68
+
69
  *Effects:* Calls `delete` on `ptr`.
70
 
 
 
71
  ##### `default_delete<T[]>` <a id="unique.ptr.dltr.dflt1">[[unique.ptr.dltr.dflt1]]</a>
72
 
73
  ``` cpp
74
  namespace std {
75
  template<class T> struct default_delete<T[]> {
 
82
 
83
  ``` cpp
84
  template<class U> default_delete(const default_delete<U[]>& other) noexcept;
85
  ```
86
 
87
+ *Constraints:* `U(*)[]` is convertible to `T(*)[]`.
88
+
89
+ *Effects:* Constructs a `default_delete` object from another
90
  `default_delete<U[]>` object.
91
 
 
 
 
92
  ``` cpp
93
  template<class U> void operator()(U* ptr) const;
94
  ```
95
 
96
+ *Mandates:* `U` is a complete type.
97
+
98
+ *Constraints:* `U(*)[]` is convertible to `T(*)[]`.
99
+
100
  *Effects:* Calls `delete[]` on `ptr`.
101
 
 
 
 
 
102
  #### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
103
 
104
  ``` cpp
105
  namespace std {
106
  template<class T, class D = default_delete<T>> class unique_ptr {
 
122
  // [unique.ptr.single.dtor], destructor
123
  ~unique_ptr();
124
 
125
  // [unique.ptr.single.asgn], assignment
126
  unique_ptr& operator=(unique_ptr&& u) noexcept;
127
+ template<class U, class E>
128
+ unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
129
  unique_ptr& operator=(nullptr_t) noexcept;
130
 
131
  // [unique.ptr.single.observers], observers
132
  add_lvalue_reference_t<T> operator*() const;
133
  pointer operator->() const noexcept;
 
147
  };
148
  }
149
  ```
150
 
151
  The default type for the template parameter `D` is `default_delete`. A
152
+ client-supplied template argument `D` shall be a function object type
153
+ [[function.objects]], lvalue reference to function, or lvalue reference
154
  to function object type for which, given a value `d` of type `D` and a
155
  value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
156
  is valid and has the effect of disposing of the pointer as appropriate
157
  for that deleter.
158
 
159
+ If the deleter’s type `D` is not a reference type, `D` shall meet the
160
+ *Cpp17Destructible* requirements ([[cpp17.destructible]]).
161
 
162
  If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
163
+ denotes a type [[temp.deduct]], then `unique_ptr<T,
164
  D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
165
  Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
166
  `element_type*`. The type `unique_ptr<T,
167
+ D>::pointer` shall meet the *Cpp17NullablePointer* requirements (
168
+ [[cpp17.nullablepointer]]).
169
 
170
+ [*Example 1*: Given an allocator type `X` ([[cpp17.allocator]]) and
171
+ letting `A` be a synonym for `allocator_traits<X>`, the types
172
  `A::pointer`, `A::const_pointer`, `A::void_pointer`, and
173
  `A::const_void_pointer` may be used as
174
  `unique_ptr<T, D>::pointer`. — *end example*]
175
 
176
+ ##### Constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
177
 
178
  ``` cpp
179
  constexpr unique_ptr() noexcept;
180
  constexpr unique_ptr(nullptr_t) noexcept;
181
  ```
182
 
183
+ *Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
184
+ ([[cpp17.defaultconstructible]]), and that construction does not throw
185
+ an exception.
186
+
187
+ *Constraints:* `is_pointer_v<deleter_type>` is `false` and
188
+ `is_default_constructible_v<deleter_type>` is `true`.
189
 
190
  *Effects:* Constructs a `unique_ptr` object that owns nothing,
191
  value-initializing the stored pointer and the stored deleter.
192
 
193
+ *Ensures:* `get() == nullptr`. `get_deleter()` returns a reference to
194
+ the stored deleter.
 
 
 
 
195
 
196
  ``` cpp
197
  explicit unique_ptr(pointer p) noexcept;
198
  ```
199
 
200
+ *Constraints:* `is_pointer_v<deleter_type>` is `false` and
201
+ `is_default_constructible_v<deleter_type>` is `true`.
202
+
203
+ *Mandates:* This constructor is not selected by class template argument
204
+ deduction [[over.match.class.deduct]].
205
+
206
+ *Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
207
+ ([[cpp17.defaultconstructible]]), and that construction does not throw
208
+ an exception.
209
 
210
  *Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
211
  stored pointer with `p` and value-initializing the stored deleter.
212
 
213
+ *Ensures:* `get() == p`. `get_deleter()` returns a reference to the
214
+ stored deleter.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  ``` cpp
217
+ unique_ptr(pointer p, const D& d) noexcept;
218
+ unique_ptr(pointer p, remove_reference_t<D>&& d) noexcept;
219
  ```
220
 
221
+ *Constraints:* `is_constructible_v<D, decltype(d)>` is `true`.
222
 
223
+ *Mandates:* These constructors are not selected by class template
224
+ argument deduction [[over.match.class.deduct]].
 
 
 
 
225
 
226
+ *Preconditions:* For the first constructor, if `D` is not a reference
227
+ type, `D` meets the *Cpp17CopyConstructible* requirements and such
228
+ construction does not exit via an exception. For the second constructor,
229
+ if `D` is not a reference type, `D` meets the *Cpp17MoveConstructible*
230
+ requirements and such construction does not exit via an exception.
231
 
232
  *Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
233
  the stored pointer with `p` and initializing the deleter from
234
  `std::forward<decltype(d)>(d)`.
235
 
236
+ *Ensures:* `get() == p`. `get_deleter()` returns a reference to the
237
+ stored deleter. If `D` is a reference type then `get_deleter()` returns
238
+ a reference to the lvalue `d`.
239
 
240
+ *Remarks:* If `D` is a reference type, the second constructor is defined
241
+ as deleted.
 
 
 
 
 
 
242
 
243
  [*Example 1*:
244
 
245
  ``` cpp
246
  D d;
247
+ unique_ptr<int, D> p1(new int, D()); // D must be Cpp17MoveConstructible
248
+ unique_ptr<int, D> p2(new int, d); // D must be Cpp17CopyConstructible
249
  unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
250
  unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
251
  // with reference deleter type
252
  ```
253
 
 
255
 
256
  ``` cpp
257
  unique_ptr(unique_ptr&& u) noexcept;
258
  ```
259
 
260
+ *Constraints:* `is_move_constructible_v<D>` is `true`.
 
 
 
261
 
262
+ *Preconditions:* If `D` is not a reference type, `D` meets the
263
+ *Cpp17MoveConstructible* requirements ([[cpp17.moveconstructible]]).
264
+ Construction of the deleter from an rvalue of type `D` does not throw an
265
+ exception.
266
 
267
+ *Effects:* Constructs a `unique_ptr` from `u`. If `D` is a reference
268
+ type, this deleter is copy constructed from `u`’s deleter; otherwise,
269
+ this deleter is move constructed from `u`’s deleter.
270
+
271
+ [*Note 1*: The construction of the deleter can be implemented with
272
  `std::forward<D>`. — *end note*]
273
 
274
+ *Ensures:* `get()` yields the value `u.get()` yielded before the
275
+ construction. `u.get() == nullptr`. `get_deleter()` returns a reference
276
+ to the stored deleter that was constructed from `u.get_deleter()`. If
277
+ `D` is a reference type then `get_deleter()` and `u.get_deleter()` both
278
+ reference the same lvalue deleter.
279
 
280
  ``` cpp
281
  template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
282
  ```
283
 
284
+ *Constraints:*
285
+
286
+ - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
287
+ - `U` is not an array type, and
288
+ - either `D` is a reference type and `E` is the same type as `D`, or `D`
289
+ is not a reference type and `E` is implicitly convertible to `D`.
290
+
291
+ *Preconditions:* If `E` is not a reference type, construction of the
292
+ deleter from an rvalue of type `E` is well-formed and does not throw an
293
  exception. Otherwise, `E` is a reference type and construction of the
294
+ deleter from an lvalue of type `E` is well-formed and does not throw an
295
+ exception.
296
 
297
+ *Effects:* Constructs a `unique_ptr` from `u`. If `E` is a reference
298
+ type, this deleter is copy constructed from `u`’s deleter; otherwise,
299
+ this deleter is move constructed from `u`’s deleter.
 
 
 
 
 
 
 
 
 
300
 
301
  [*Note 2*: The deleter constructor can be implemented with
302
  `std::forward<E>`. — *end note*]
303
 
304
+ *Ensures:* `get()` yields the value `u.get()` yielded before the
305
+ construction. `u.get() == nullptr`. `get_deleter()` returns a reference
306
+ to the stored deleter that was constructed from `u.get_deleter()`.
307
 
308
+ ##### Destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
309
 
310
  ``` cpp
311
  ~unique_ptr();
312
  ```
313
 
314
+ *Preconditions:* The expression `get_deleter()(get())` is well-formed,
315
+ has well-defined behavior, and does not throw exceptions.
316
 
317
  [*Note 3*: The use of `default_delete` requires `T` to be a complete
318
  type. — *end note*]
319
 
320
  *Effects:* If `get() == nullptr` there are no effects. Otherwise
321
  `get_deleter()(get())`.
322
 
323
+ ##### Assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
324
 
325
  ``` cpp
326
  unique_ptr& operator=(unique_ptr&& u) noexcept;
327
  ```
328
 
329
+ *Constraints:* `is_move_assignable_v<D>` is `true`.
330
+
331
+ *Preconditions:* If `D` is not a reference type, `D` meets the
332
+ *Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]) and
333
+ assignment of the deleter from an rvalue of type `D` does not throw an
334
  exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
335
+ meets the *Cpp17CopyAssignable* requirements and assignment of the
336
+ deleter from an lvalue of type `D` does not throw an exception.
337
 
338
+ *Effects:* Calls `reset(u.release())` followed by
 
339
  `get_deleter() = std::forward<D>(u.get_deleter())`.
340
 
341
  *Returns:* `*this`.
342
 
343
+ *Ensures:* `u.get() == nullptr`.
344
+
345
  ``` cpp
346
  template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
347
  ```
348
 
349
+ *Constraints:*
 
 
 
 
 
 
 
350
 
351
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
352
  and
353
  - `U` is not an array type, and
354
  - `is_assignable_v<D&, E&&>` is `true`.
355
 
356
+ *Preconditions:* If `E` is not a reference type, assignment of the
357
+ deleter from an rvalue of type `E` is well-formed and does not throw an
358
+ exception. Otherwise, `E` is a reference type and assignment of the
359
+ deleter from an lvalue of type `E` is well-formed and does not throw an
360
+ exception.
361
+
362
+ *Effects:* Calls `reset(u.release())` followed by
363
  `get_deleter() = std::forward<E>(u.get_deleter())`.
364
 
365
  *Returns:* `*this`.
366
 
367
+ *Ensures:* `u.get() == nullptr`.
368
+
369
  ``` cpp
370
  unique_ptr& operator=(nullptr_t) noexcept;
371
  ```
372
 
373
  *Effects:* As if by `reset()`.
374
 
375
+ *Ensures:* `get() == nullptr`.
376
 
377
  *Returns:* `*this`.
378
 
379
+ ##### Observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
380
 
381
  ``` cpp
382
  add_lvalue_reference_t<T> operator*() const;
383
  ```
384
 
385
+ *Preconditions:* `get() != nullptr`.
386
 
387
  *Returns:* `*get()`.
388
 
389
  ``` cpp
390
  pointer operator->() const noexcept;
391
  ```
392
 
393
+ *Preconditions:* `get() != nullptr`.
394
 
395
  *Returns:* `get()`.
396
 
397
  [*Note 4*: The use of this function typically requires that `T` be a
398
  complete type. — *end note*]
 
414
  explicit operator bool() const noexcept;
415
  ```
416
 
417
  *Returns:* `get() != nullptr`.
418
 
419
+ ##### Modifiers <a id="unique.ptr.single.modifiers">[[unique.ptr.single.modifiers]]</a>
420
 
421
  ``` cpp
422
  pointer release() noexcept;
423
  ```
424
 
425
+ *Ensures:* `get() == nullptr`.
426
 
427
  *Returns:* The value `get()` had at the start of the call to `release`.
428
 
429
  ``` cpp
430
  void reset(pointer p = pointer()) noexcept;
431
  ```
432
 
433
+ *Preconditions:* The expression `get_deleter()(get())` is well-formed,
434
+ has well-defined behavior, and does not throw exceptions.
435
 
436
  *Effects:* Assigns `p` to the stored pointer, and then if and only if
437
  the old value of the stored pointer, `old_p`, was not equal to
438
  `nullptr`, calls `get_deleter()(old_p)`.
439
 
440
  [*Note 5*: The order of these operations is significant because the
441
  call to `get_deleter()` may destroy `*this`. — *end note*]
442
 
443
+ *Ensures:* `get() == p`.
444
 
445
  [*Note 6*: The postcondition does not hold if the call to
446
  `get_deleter()` destroys `*this` since `this->get()` is no longer a
447
  valid expression. — *end note*]
448
 
449
  ``` cpp
450
  void swap(unique_ptr& u) noexcept;
451
  ```
452
 
453
+ *Preconditions:* `get_deleter()` is swappable [[swappable.requirements]]
454
+ and does not throw an exception under `swap`.
 
455
 
456
  *Effects:* Invokes `swap` on the stored pointers and on the stored
457
  deleters of `*this` and `u`.
458
 
459
  #### `unique_ptr` for array objects with a runtime length <a id="unique.ptr.runtime">[[unique.ptr.runtime]]</a>
 
521
  Descriptions are provided below only for members that differ from the
522
  primary template.
523
 
524
  The template argument `T` shall be a complete type.
525
 
526
+ ##### Constructors <a id="unique.ptr.runtime.ctor">[[unique.ptr.runtime.ctor]]</a>
527
 
528
  ``` cpp
529
  template<class U> explicit unique_ptr(U p) noexcept;
530
  ```
531
 
532
  This constructor behaves the same as the constructor in the primary
533
+ template that takes a single parameter of type `pointer`.
534
+
535
+ *Constraints:*
536
 
537
  - `U` is the same type as `pointer`, or
538
  - `pointer` is the same type as `element_type*`, `U` is a pointer type
539
  `V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
540
 
 
542
  template<class U> unique_ptr(U p, see below d) noexcept;
543
  template<class U> unique_ptr(U p, see below d) noexcept;
544
  ```
545
 
546
  These constructors behave the same as the constructors in the primary
547
+ template that take a parameter of type `pointer` and a second parameter.
548
+
549
+ *Constraints:*
550
 
551
  - `U` is the same type as `pointer`,
552
  - `U` is `nullptr_t`, or
553
  - `pointer` is the same type as `element_type*`, `U` is a pointer type
554
  `V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
555
 
556
  ``` cpp
557
+ template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
 
558
  ```
559
 
560
+ This constructor behaves the same as in the primary template.
561
+
562
+ *Constraints:* Where `UP` is `unique_ptr<U, E>`:
563
 
564
  - `U` is an array type, and
565
  - `pointer` is the same type as `element_type*`, and
566
  - `UP::pointer` is the same type as `UP::element_type*`, and
567
  - `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
568
  - either `D` is a reference type and `E` is the same type as `D`, or `D`
569
  is not a reference type and `E` is implicitly convertible to `D`.
570
 
571
+ [*Note 1*: This replaces the *Constraints:* specification of the
572
+ primary template. — *end note*]
573
 
574
+ ##### Assignment <a id="unique.ptr.runtime.asgn">[[unique.ptr.runtime.asgn]]</a>
575
 
576
  ``` cpp
577
+ template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u)noexcept;
 
578
  ```
579
 
580
+ This operator behaves the same as in the primary template.
581
+
582
+ *Constraints:* Where `UP` is `unique_ptr<U, E>`:
583
 
584
  - `U` is an array type, and
585
  - `pointer` is the same type as `element_type*`, and
586
  - `UP::pointer` is the same type as `UP::element_type*`, and
587
  - `UP::element_type(*)[]` is convertible to `element_type(*)[]`, and
588
  - `is_assignable_v<D&, E&&>` is `true`.
589
 
590
+ [*Note 2*: This replaces the *Constraints:* specification of the
591
+ primary template. — *end note*]
592
 
593
+ ##### Observers <a id="unique.ptr.runtime.observers">[[unique.ptr.runtime.observers]]</a>
594
 
595
  ``` cpp
596
  T& operator[](size_t i) const;
597
  ```
598
 
599
+ *Preconditions:* `i` < the number of elements in the array to which the
600
  stored pointer points.
601
 
602
  *Returns:* `get()[i]`.
603
 
604
+ ##### Modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
605
 
606
  ``` cpp
607
  void reset(nullptr_t p = nullptr) noexcept;
608
  ```
609
 
 
612
  ``` cpp
613
  template<class U> void reset(U p) noexcept;
614
  ```
615
 
616
  This function behaves the same as the `reset` member of the primary
617
+ template.
618
+
619
+ *Constraints:*
620
 
621
  - `U` is the same type as `pointer`, or
622
  - `pointer` is the same type as `element_type*`, `U` is a pointer type
623
  `V*`, and `V(*)[]` is convertible to `element_type(*)[]`.
624
 
625
+ #### Creation <a id="unique.ptr.create">[[unique.ptr.create]]</a>
626
 
627
  ``` cpp
628
  template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
629
  ```
630
 
631
+ *Constraints:* `T` is not an array type.
 
632
 
633
  *Returns:* `unique_ptr<T>(new T(std::forward<Args>(args)...))`.
634
 
635
  ``` cpp
636
  template<class T> unique_ptr<T> make_unique(size_t n);
637
  ```
638
 
639
+ *Constraints:* `T` is an array of unknown bound.
 
640
 
641
  *Returns:* `unique_ptr<T>(new remove_extent_t<T>[n]())`.
642
 
643
  ``` cpp
644
  template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
645
  ```
646
 
647
+ *Constraints:* `T` is an array of known bound.
 
648
 
649
+ ``` cpp
650
+ template<class T> unique_ptr<T> make_unique_for_overwrite();
651
+ ```
652
+
653
+ *Constraints:* `T` is not an array type.
654
+
655
+ *Returns:* `unique_ptr<T>(new T)`.
656
+
657
+ ``` cpp
658
+ template<class T> unique_ptr<T> make_unique_for_overwrite(size_t n);
659
+ ```
660
+
661
+ *Constraints:* `T` is an array of unknown bound.
662
+
663
+ *Returns:* `unique_ptr<T>(new remove_extent_t<T>[n])`.
664
+
665
+ ``` cpp
666
+ template<class T, class... Args> unspecified make_unique_for_overwrite(Args&&...) = delete;
667
+ ```
668
+
669
+ *Constraints:* `T` is an array of known bound.
670
+
671
+ #### Specialized algorithms <a id="unique.ptr.special">[[unique.ptr.special]]</a>
672
 
673
  ``` cpp
674
  template<class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
675
  ```
676
 
677
+ *Constraints:* `is_swappable_v<D>` is `true`.
 
678
 
679
  *Effects:* Calls `x.swap(y)`.
680
 
681
  ``` cpp
682
  template<class T1, class D1, class T2, class D2>
683
  bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
684
  ```
685
 
686
  *Returns:* `x.get() == y.get()`.
687
 
 
 
 
 
 
 
 
688
  ``` cpp
689
  template<class T1, class D1, class T2, class D2>
690
  bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
691
  ```
692
 
693
+ Let `CT` denote
694
 
695
  ``` cpp
696
  common_type_t<typename unique_ptr<T1, D1>::pointer,
697
  typename unique_ptr<T2, D2>::pointer>
698
  ```
699
 
700
+ *Mandates:*
 
 
701
 
702
+ - `unique_ptr<T1, D1>::pointer` is implicitly convertible to `CT` and
703
+ - `unique_ptr<T2, D2>::pointer` is implicitly convertible to `CT`.
704
 
705
+ *Preconditions:* The specialization `less<CT>` is a function object
706
+ type [[function.objects]] that induces a strict weak
707
+ ordering [[alg.sorting]] on the pointer values.
708
 
709
+ *Returns:* `less<CT>()(x.get(), y.get())`.
 
 
 
 
 
710
 
711
  ``` cpp
712
  template<class T1, class D1, class T2, class D2>
713
  bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
714
  ```
715
 
716
  *Returns:* `y < x`.
717
 
718
+ ``` cpp
719
+ template<class T1, class D1, class T2, class D2>
720
+ bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
721
+ ```
722
+
723
+ *Returns:* `!(y < x)`.
724
+
725
  ``` cpp
726
  template<class T1, class D1, class T2, class D2>
727
  bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
728
  ```
729
 
730
  *Returns:* `!(x < y)`.
731
 
732
+ ``` cpp
733
+ template<class T1, class D1, class T2, class D2>
734
+ requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer,
735
+ typename unique_ptr<T2, D2>::pointer>
736
+ compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer,
737
+ typename unique_ptr<T2, D2>::pointer>
738
+ operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
739
+ ```
740
+
741
+ *Returns:* `compare_three_way()(x.get(), y.get())`.
742
+
743
  ``` cpp
744
  template<class T, class D>
745
  bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
 
 
746
  ```
747
 
748
  *Returns:* `!x`.
749
 
 
 
 
 
 
 
 
 
 
750
  ``` cpp
751
  template<class T, class D>
752
  bool operator<(const unique_ptr<T, D>& x, nullptr_t);
753
  template<class T, class D>
754
  bool operator<(nullptr_t, const unique_ptr<T, D>& x);
755
  ```
756
 
757
+ *Preconditions:* The specialization `less<unique_ptr<T, D>::pointer>` is
758
+ a function object type [[function.objects]] that induces a strict weak
759
+ ordering [[alg.sorting]] on the pointer values.
760
 
761
  *Returns:* The first function template returns
762
+
763
+ ``` cpp
764
+ less<unique_ptr<T, D>::pointer>()(x.get(), nullptr)
765
+ ```
766
+
767
+ The second function template returns
768
+
769
+ ``` cpp
770
+ less<unique_ptr<T, D>::pointer>()(nullptr, x.get())
771
+ ```
772
 
773
  ``` cpp
774
  template<class T, class D>
775
  bool operator>(const unique_ptr<T, D>& x, nullptr_t);
776
  template<class T, class D>
 
798
  ```
799
 
800
  *Returns:* The first function template returns `!(x < nullptr)`. The
801
  second function template returns `!(nullptr < x)`.
802
 
803
+ ``` cpp
804
+ template<class T, class D>
805
+ requires three_way_comparable_with<typename unique_ptr<T, D>::pointer, nullptr_t>
806
+ compare_three_way_result_t<typename unique_ptr<T, D>::pointer, nullptr_t>
807
+ operator<=>(const unique_ptr<T, D>& x, nullptr_t);
808
+ ```
809
+
810
+ *Returns:* `compare_three_way()(x.get(), nullptr)`.
811
+
812
+ #### I/O <a id="unique.ptr.io">[[unique.ptr.io]]</a>
813
+
814
+ ``` cpp
815
+ template<class E, class T, class Y, class D>
816
+ basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);
817
+ ```
818
+
819
+ *Constraints:* `os << p.get()` is a valid expression.
820
+
821
+ *Effects:* Equivalent to: `os << p.get();`
822
+
823
+ *Returns:* `os`.
824
+