From Jason Turner

[smartptr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmnj87b_u/{from.md → to.md} +110 -54
tmp/tmpmnj87b_u/{from.md → to.md} RENAMED
@@ -50,10 +50,14 @@ namespace std {
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 D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
56
 
57
  template<class T1, class D1, class T2, class D2>
58
  bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
59
  template<class T1, class D1, class T2, class D2>
@@ -185,11 +189,11 @@ namespace std {
185
  unique_ptr& operator=(unique_ptr&& u) noexcept;
186
  template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
187
  unique_ptr& operator=(nullptr_t) noexcept;
188
 
189
  // [unique.ptr.single.observers], observers
190
- typename add_lvalue_reference<T>::type operator*() const;
191
  pointer operator->() const noexcept;
192
  pointer get() const noexcept;
193
  deleter_type& get_deleter() noexcept;
194
  const deleter_type& get_deleter() const noexcept;
195
  explicit operator bool() const noexcept;
@@ -215,16 +219,14 @@ is valid and has the effect of disposing of the pointer as appropriate
215
  for that deleter.
216
 
217
  If the deleter’s type `D` is not a reference type, `D` shall satisfy the
218
  requirements of `Destructible` (Table  [[destructible]]).
219
 
220
- If the type `remove_reference<D>::type::pointer` exists, then
221
- `unique_ptr<T,
222
- D>::pointer` shall be a synonym for
223
- `remove_reference<D>::type::pointer`. Otherwise
224
- `unique_ptr<T, D>::pointer` shall be a synonym for `T*`. The type
225
- `unique_ptr<T,
226
  D>::pointer` shall satisfy the requirements of `NullablePointer` (
227
  [[nullablepointer.requirements]]).
228
 
229
  Given an allocator type `X` ([[allocator.requirements]]) and letting
230
  `A` be a synonym for `allocator_traits<X>`, the types `A::pointer`,
@@ -420,18 +422,17 @@ unique_ptr& operator=(unique_ptr&& u) noexcept;
420
  ```
421
 
422
  *Requires:* If `D` is not a reference type, `D` shall satisfy the
423
  requirements of `MoveAssignable` (Table  [[moveassignable]]) and
424
  assignment of the deleter from an rvalue of type `D` shall not throw an
425
- exception. Otherwise, `D` is a reference type;
426
- `remove_reference<D>::type` shall satisfy the `CopyAssignable`
427
- requirements and assignment of the deleter from an lvalue of type `D`
428
- shall not throw an exception.
429
 
430
  *Effects:* Transfers ownership from `u` to `*this` as if by calling
431
- `reset(u.release())` followed by an assignment from
432
- `std::forward<D>(u.get_deleter())`.
433
 
434
  *Returns:* `*this`.
435
 
436
  ``` cpp
437
  template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
@@ -448,12 +449,12 @@ unless:
448
 
449
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer` and
450
  - `U` is not an array type.
451
 
452
  *Effects:* Transfers ownership from `u` to `*this` as if by calling
453
- `reset(u.release())` followed by an assignment from
454
- `std::forward<D>(u.get_deleter())`.
455
 
456
  *Returns:* `*this`.
457
 
458
  ``` cpp
459
  unique_ptr& operator=(nullptr_t) noexcept;
@@ -466,11 +467,11 @@ unique_ptr& operator=(nullptr_t) noexcept;
466
  *Returns:* `*this`.
467
 
468
  ##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
469
 
470
  ``` cpp
471
- typename add_lvalue_reference<T>::type operator*() const;
472
  ```
473
 
474
  *Requires:* `get() != nullptr`.
475
 
476
  *Returns:* `*get()`.
@@ -629,18 +630,41 @@ stored pointer points.
629
  *Returns:* `get()[i]`.
630
 
631
  ##### `unique_ptr` modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
632
 
633
  ``` cpp
634
- void reset(pointer p = pointer()) noexcept;
635
  void reset(nullptr_t p) noexcept;
636
  ```
637
 
638
- *Effects:* If `get() == nullptr` there are no effects. Otherwise
639
- `get_deleter()(get())`.
640
 
641
- `get() == p`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
 
643
  #### `unique_ptr` specialized algorithms <a id="unique.ptr.special">[[unique.ptr.special]]</a>
644
 
645
  ``` cpp
646
  template <class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
@@ -802,12 +826,12 @@ namespace std {
802
  // [util.smartptr.shared.const], constructors:
803
  constexpr shared_ptr() noexcept;
804
  template<class Y> explicit shared_ptr(Y* p);
805
  template<class Y, class D> shared_ptr(Y* p, D d);
806
  template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
807
- template <class D> shared_ptr(nullptr_t p, D d)
808
- template <class D, class A> shared_ptr(nullptr_t p, D d, A a)
809
  template<class Y> shared_ptr(const shared_ptr<Y>& r, T* p) noexcept;
810
  shared_ptr(const shared_ptr& r) noexcept;
811
  template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
812
  shared_ptr(shared_ptr&& r) noexcept;
813
  template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
@@ -934,11 +958,11 @@ races.
934
  constexpr shared_ptr() noexcept;
935
  ```
936
 
937
  *Effects:* Constructs an *empty* `shared_ptr` object.
938
 
939
- *Postconditions:* `use_count() == 0 && get() == 0`.
940
 
941
  ``` cpp
942
  template<class Y> explicit shared_ptr(Y* p);
943
  ```
944
 
@@ -992,19 +1016,19 @@ template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
992
  To avoid the possibility of a dangling pointer, the user of this
993
  constructor must ensure that `p` remains valid at least until the
994
  ownership group of `r` is destroyed.
995
 
996
  This constructor allows creation of an *empty* `shared_ptr` instance
997
- with a non-NULL stored pointer.
998
 
999
  ``` cpp
1000
  shared_ptr(const shared_ptr& r) noexcept;
1001
  template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
1002
  ```
1003
 
1004
- *Requires:* The second constructor shall not participate in the overload
1005
- resolution unless `Y*` is implicitly convertible to `T*`.
1006
 
1007
  *Effects:* If `r` is *empty*, constructs an *empty* `shared_ptr` object;
1008
  otherwise, constructs a `shared_ptr` object that *shares ownership* with
1009
  `r`.
1010
 
@@ -1019,11 +1043,11 @@ The second constructor shall not participate in overload resolution
1019
  unless `Y*` is convertible to `T*`.
1020
 
1021
  *Effects:* Move-constructs a `shared_ptr` instance from `r`.
1022
 
1023
  *Postconditions:* `*this` shall contain the old value of `r`. `r` shall
1024
- be *empty*. `r.get() == 0.`
1025
 
1026
  ``` cpp
1027
  template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
1028
  ```
1029
 
@@ -1047,11 +1071,11 @@ complete type. The expression `delete r.release()` shall be well formed,
1047
  shall have well defined behavior, and shall not throw exceptions.
1048
 
1049
  *Effects:* Constructs a `shared_ptr` object that stores and *owns*
1050
  `r.release()`.
1051
 
1052
- *Postconditions:* `use_count() == 1` `&&` `r.get() == 0`.
1053
 
1054
  *Throws:* `bad_alloc`, or an *implementation-defined* exception when a
1055
  resource other than memory could not be obtained.
1056
 
1057
  If an exception is thrown, the constructor has no effect.
@@ -1204,11 +1228,11 @@ bool unique() const noexcept;
1204
 
1205
  *Returns:* `use_count() == 1`.
1206
 
1207
  `unique()` may be faster than `use_count()`. If you are using `unique()`
1208
  to implement copy on write, do not rely on a specific value when
1209
- `get() == 0`.
1210
 
1211
  ``` cpp
1212
  explicit operator bool() const noexcept;
1213
  ```
1214
 
@@ -1254,13 +1278,13 @@ the newly constructed object of type `T`.
1254
  *Postconditions:* `get() != 0 && use_count() == 1`
1255
 
1256
  *Throws:* `bad_alloc`, or an exception thrown from `A::allocate` or from
1257
  the constructor of `T`.
1258
 
1259
- *Remarks:* Implementations are encouraged, but not required, to perform
1260
- no more than one memory allocation. This provides efficiency equivalent
1261
- to an intrusive smart pointer.
1262
 
1263
  These functions will typically allocate more memory than `sizeof(T)` to
1264
  allow for internal bookkeeping structures such as the reference counts.
1265
 
1266
  ##### `shared_ptr` comparison <a id="util.smartptr.shared.cmp">[[util.smartptr.shared.cmp]]</a>
@@ -1274,11 +1298,11 @@ template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_
1274
  ``` cpp
1275
  template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
1276
  ```
1277
 
1278
  *Returns:* `less<V>()(a.get(), b.get())`, where `V` is the composite
1279
- pointer type ([[expr.rel]]) of `T*` and `U*`.
1280
 
1281
  Defining a comparison operator allows `shared_ptr` objects to be used as
1282
  keys in associative containers.
1283
 
1284
  ``` cpp
@@ -1411,14 +1435,14 @@ undefined behavior, attempting to delete the same object twice.
1411
  ``` cpp
1412
  template<class D, class T> D* get_deleter(const shared_ptr<T>& p) noexcept;
1413
  ```
1414
 
1415
  *Returns:* If `p` *owns* a deleter `d` of type cv-unqualified `D`,
1416
- returns `&d`; otherwise returns `0`. The returned pointer remains valid
1417
- as long as there exists a `shared_ptr` instance that owns `d`. It is
1418
- unspecified whether the pointer remains valid longer than that. This can
1419
- happen if the implementation doesn’t destroy the deleter until all
1420
  `weak_ptr` instances that share ownership with `p` have been destroyed.
1421
 
1422
  ##### `shared_ptr` I/O <a id="util.smartptr.shared.io">[[util.smartptr.shared.io]]</a>
1423
 
1424
  ``` cpp
@@ -1445,29 +1469,33 @@ namespace std {
1445
  // [util.smartptr.weak.const], constructors
1446
  constexpr weak_ptr() noexcept;
1447
  template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
1448
  weak_ptr(weak_ptr const& r) noexcept;
1449
  template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
 
 
1450
 
1451
  // [util.smartptr.weak.dest], destructor
1452
  ~weak_ptr();
1453
 
1454
  // [util.smartptr.weak.assign], assignment
1455
  weak_ptr& operator=(weak_ptr const& r) noexcept;
1456
  template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
1457
  template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
 
 
1458
 
1459
  // [util.smartptr.weak.mod], modifiers
1460
  void swap(weak_ptr& r) noexcept;
1461
  void reset() noexcept;
1462
 
1463
  // [util.smartptr.weak.obs], observers
1464
  long use_count() const noexcept;
1465
  bool expired() const noexcept;
1466
  shared_ptr<T> lock() const noexcept;
1467
- template<class U> bool owner_before(shared_ptr<U> const& b);
1468
- template<class U> bool owner_before(weak_ptr<U> const& b);
1469
  };
1470
 
1471
  // [util.smartptr.weak.spec], specialized algorithms
1472
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
1473
  } // namespace std
@@ -1491,19 +1519,32 @@ constexpr weak_ptr() noexcept;
1491
  weak_ptr(const weak_ptr& r) noexcept;
1492
  template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
1493
  template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
1494
  ```
1495
 
1496
- *Requires:* The second and third constructors shall not participate in
1497
- the overload resolution unless `Y*` is implicitly convertible to `T*`.
1498
 
1499
  *Effects:* If `r` is *empty*, constructs an *empty* `weak_ptr` object;
1500
  otherwise, constructs a `weak_ptr` object that *shares ownership* with
1501
  `r` and stores a copy of the pointer stored in `r`.
1502
 
1503
  *Postconditions:* `use_count() == r.use_count()`.
1504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1505
  ##### `weak_ptr` destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
1506
 
1507
  ``` cpp
1508
  ~weak_ptr();
1509
  ```
@@ -1522,10 +1563,21 @@ template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
1522
  *Effects:* Equivalent to `weak_ptr(r).swap(*this)`.
1523
 
1524
  *Remarks:* The implementation may meet the effects (and the implied
1525
  guarantees) via different means, without creating a temporary.
1526
 
 
 
 
 
 
 
 
 
 
 
 
1527
  ##### `weak_ptr` modifiers <a id="util.smartptr.weak.mod">[[util.smartptr.weak.mod]]</a>
1528
 
1529
  ``` cpp
1530
  void swap(weak_ptr& r) noexcept;
1531
  ```
@@ -1559,15 +1611,16 @@ bool expired() const noexcept;
1559
 
1560
  ``` cpp
1561
  shared_ptr<T> lock() const noexcept;
1562
  ```
1563
 
1564
- *Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`.
 
1565
 
1566
  ``` cpp
1567
- template<class U> bool owner_before(shared_ptr<U> const& b);
1568
- template<class U> bool owner_before(weak_ptr<U> const& b);
1569
  ```
1570
 
1571
  *Returns:* An unspecified value such that
1572
 
1573
  - `x.owner_before(y)` defines a strict weak ordering as defined
@@ -1583,11 +1636,11 @@ template<class U> bool owner_before(weak_ptr<U> const& b);
1583
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
1584
  ```
1585
 
1586
  *Effects:* Equivalent to `a.swap(b)`.
1587
 
1588
- ##### Class template `owner_less` <a id="util.smartptr.ownerless">[[util.smartptr.ownerless]]</a>
1589
 
1590
  The class template `owner_less` allows ownership-based mixed comparisons
1591
  of shared and weak pointers.
1592
 
1593
  ``` cpp
@@ -1814,11 +1867,11 @@ template<class T>
1814
  template<class T>
1815
  bool atomic_compare_exchange_weak(
1816
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
1817
  ```
1818
 
1819
- *Requires:* `p` shall not be null.
1820
 
1821
  *Returns:*
1822
  `atomic_compare_exchange_weak_explicit(p, v, w, memory_order_seq_cst, memory_order_seq_cst)`.
1823
 
1824
  *Throws:* Nothing.
@@ -1841,11 +1894,11 @@ template<class T>
1841
  bool atomic_compare_exchange_strong_explicit(
1842
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
1843
  memory_order success, memory_order failure);
1844
  ```
1845
 
1846
- *Requires:* `p` shall not be null.
1847
 
1848
  *Requires:* `failure` shall not be `memory_order_release`,
1849
  `memory_order_acq_rel`, or stronger than `success`.
1850
 
1851
  *Effects:* If `*p` is equivalent to `*v`, assigns `w` to `*p` and has
@@ -1867,20 +1920,23 @@ See  [[atomics.types.operations]].
1867
 
1868
  ``` cpp
1869
  template <class T, class D> struct hash<unique_ptr<T, D> >;
1870
  ```
1871
 
1872
- *Requires:* The template specialization shall meet the requirements of
1873
- class template `hash` ([[unord.hash]]). For an object `p` of type `UP`,
1874
- where `UP` is `unique_ptr<T, D>`, `hash<UP>()(p)` shall evaluate to the
1875
- same value as `hash<typename UP::pointer>()(p.get())`. The
1876
- specialization `hash<typename UP::pointer>` shall be well-formed.
 
 
 
1877
 
1878
  ``` cpp
1879
  template <class T> struct hash<shared_ptr<T> >;
1880
  ```
1881
 
1882
- *Requires:* The template specialization shall meet the requirements of
1883
- class template `hash` ([[unord.hash]]). For an object `p` of type
1884
  `shared_ptr<T>`, `hash<shared_ptr<T> >()(p)` shall evaluate to the same
1885
  value as `hash<T*>()(p.get())`.
1886
 
 
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>
 
189
  unique_ptr& operator=(unique_ptr&& u) noexcept;
190
  template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
191
  unique_ptr& operator=(nullptr_t) noexcept;
192
 
193
  // [unique.ptr.single.observers], observers
194
+ add_lvalue_reference_t<T> operator*() const;
195
  pointer operator->() const noexcept;
196
  pointer get() const noexcept;
197
  deleter_type& get_deleter() noexcept;
198
  const deleter_type& get_deleter() const noexcept;
199
  explicit operator bool() const noexcept;
 
219
  for that deleter.
220
 
221
  If the deleter’s type `D` is not a reference type, `D` shall satisfy the
222
  requirements of `Destructible` (Table  [[destructible]]).
223
 
224
+ If the type `remove_reference_t<D>::pointer` exists, then `unique_ptr<T,
225
+ D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
226
+ Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for `T*`. The
227
+ type `unique_ptr<T,
 
 
228
  D>::pointer` shall satisfy the requirements of `NullablePointer` (
229
  [[nullablepointer.requirements]]).
230
 
231
  Given an allocator type `X` ([[allocator.requirements]]) and letting
232
  `A` be a synonym for `allocator_traits<X>`, the types `A::pointer`,
 
422
  ```
423
 
424
  *Requires:* If `D` is not a reference type, `D` shall satisfy the
425
  requirements of `MoveAssignable` (Table  [[moveassignable]]) and
426
  assignment of the deleter from an rvalue of type `D` shall not throw an
427
+ exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
428
+ shall satisfy the `CopyAssignable` requirements and assignment of the
429
+ deleter from an lvalue of type `D` shall not throw an exception.
 
430
 
431
  *Effects:* Transfers ownership from `u` to `*this` as if by calling
432
+ `reset(u.release())` followed by
433
+ `get_deleter() = std::forward<D>(u.get_deleter())`.
434
 
435
  *Returns:* `*this`.
436
 
437
  ``` cpp
438
  template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
 
449
 
450
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer` and
451
  - `U` is not an array type.
452
 
453
  *Effects:* Transfers ownership from `u` to `*this` as if by calling
454
+ `reset(u.release())` followed by
455
+ `get_deleter() = std::forward<E>(u.get_deleter())`.
456
 
457
  *Returns:* `*this`.
458
 
459
  ``` cpp
460
  unique_ptr& operator=(nullptr_t) noexcept;
 
467
  *Returns:* `*this`.
468
 
469
  ##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
470
 
471
  ``` cpp
472
+ add_lvalue_reference_t<T> operator*() const;
473
  ```
474
 
475
  *Requires:* `get() != nullptr`.
476
 
477
  *Returns:* `*get()`.
 
630
  *Returns:* `get()[i]`.
631
 
632
  ##### `unique_ptr` modifiers <a id="unique.ptr.runtime.modifiers">[[unique.ptr.runtime.modifiers]]</a>
633
 
634
  ``` cpp
 
635
  void reset(nullptr_t p) noexcept;
636
  ```
637
 
638
+ *Effects:* Equivalent to `reset(pointer())`.
 
639
 
640
+ #### `unique_ptr` creation <a id="unique.ptr.create">[[unique.ptr.create]]</a>
641
+
642
+ ``` cpp
643
+ template <class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
644
+ ```
645
+
646
+ *Remarks:* This function shall not participate in overload resolution
647
+ unless `T` is not an array.
648
+
649
+ *Returns:* `unique_ptr<T>(new T(std::forward<Args>(args)...))`.
650
+
651
+ ``` cpp
652
+ template <class T> unique_ptr<T> make_unique(size_t n);
653
+ ```
654
+
655
+ *Remarks:* This function shall not participate in overload resolution
656
+ unless `T` is an array of unknown bound.
657
+
658
+ *Returns:* `unique_ptr<T>(new remove_extent_t<T>[n]())`.
659
+
660
+ ``` cpp
661
+ template <class T, class... Args> unspecified make_unique(Args&&...) = delete;
662
+ ```
663
+
664
+ *Remarks:* This function shall not participate in overload resolution
665
+ unless `T` is an array of known bound.
666
 
667
  #### `unique_ptr` specialized algorithms <a id="unique.ptr.special">[[unique.ptr.special]]</a>
668
 
669
  ``` cpp
670
  template <class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
 
826
  // [util.smartptr.shared.const], constructors:
827
  constexpr shared_ptr() noexcept;
828
  template<class Y> explicit shared_ptr(Y* p);
829
  template<class Y, class D> shared_ptr(Y* p, D d);
830
  template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
831
+ template <class D> shared_ptr(nullptr_t p, D d);
832
+ template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
833
  template<class Y> shared_ptr(const shared_ptr<Y>& r, T* p) noexcept;
834
  shared_ptr(const shared_ptr& r) noexcept;
835
  template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
836
  shared_ptr(shared_ptr&& r) noexcept;
837
  template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
 
958
  constexpr shared_ptr() noexcept;
959
  ```
960
 
961
  *Effects:* Constructs an *empty* `shared_ptr` object.
962
 
963
+ *Postconditions:* `use_count() == 0 && get() == nullptr`.
964
 
965
  ``` cpp
966
  template<class Y> explicit shared_ptr(Y* p);
967
  ```
968
 
 
1016
  To avoid the possibility of a dangling pointer, the user of this
1017
  constructor must ensure that `p` remains valid at least until the
1018
  ownership group of `r` is destroyed.
1019
 
1020
  This constructor allows creation of an *empty* `shared_ptr` instance
1021
+ with a non-null stored pointer.
1022
 
1023
  ``` cpp
1024
  shared_ptr(const shared_ptr& r) noexcept;
1025
  template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
1026
  ```
1027
 
1028
+ The second constructor shall not participate in overload resolution
1029
+ unless `Y*` is implicitly convertible to `T*`.
1030
 
1031
  *Effects:* If `r` is *empty*, constructs an *empty* `shared_ptr` object;
1032
  otherwise, constructs a `shared_ptr` object that *shares ownership* with
1033
  `r`.
1034
 
 
1043
  unless `Y*` is convertible to `T*`.
1044
 
1045
  *Effects:* Move-constructs a `shared_ptr` instance from `r`.
1046
 
1047
  *Postconditions:* `*this` shall contain the old value of `r`. `r` shall
1048
+ be *empty*. `r.get() == nullptr.`
1049
 
1050
  ``` cpp
1051
  template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
1052
  ```
1053
 
 
1071
  shall have well defined behavior, and shall not throw exceptions.
1072
 
1073
  *Effects:* Constructs a `shared_ptr` object that stores and *owns*
1074
  `r.release()`.
1075
 
1076
+ *Postconditions:* `use_count() == 1` `&&` `r.get() == nullptr`.
1077
 
1078
  *Throws:* `bad_alloc`, or an *implementation-defined* exception when a
1079
  resource other than memory could not be obtained.
1080
 
1081
  If an exception is thrown, the constructor has no effect.
 
1228
 
1229
  *Returns:* `use_count() == 1`.
1230
 
1231
  `unique()` may be faster than `use_count()`. If you are using `unique()`
1232
  to implement copy on write, do not rely on a specific value when
1233
+ `get() == nullptr`.
1234
 
1235
  ``` cpp
1236
  explicit operator bool() const noexcept;
1237
  ```
1238
 
 
1278
  *Postconditions:* `get() != 0 && use_count() == 1`
1279
 
1280
  *Throws:* `bad_alloc`, or an exception thrown from `A::allocate` or from
1281
  the constructor of `T`.
1282
 
1283
+ *Remarks:* Implementations should perform no more than one memory
1284
+ allocation. This provides efficiency equivalent to an intrusive smart
1285
+ pointer.
1286
 
1287
  These functions will typically allocate more memory than `sizeof(T)` to
1288
  allow for internal bookkeeping structures such as the reference counts.
1289
 
1290
  ##### `shared_ptr` comparison <a id="util.smartptr.shared.cmp">[[util.smartptr.shared.cmp]]</a>
 
1298
  ``` cpp
1299
  template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
1300
  ```
1301
 
1302
  *Returns:* `less<V>()(a.get(), b.get())`, where `V` is the composite
1303
+ pointer type (Clause  [[expr]]) of `T*` and `U*`.
1304
 
1305
  Defining a comparison operator allows `shared_ptr` objects to be used as
1306
  keys in associative containers.
1307
 
1308
  ``` cpp
 
1435
  ``` cpp
1436
  template<class D, class T> D* get_deleter(const shared_ptr<T>& p) noexcept;
1437
  ```
1438
 
1439
  *Returns:* If `p` *owns* a deleter `d` of type cv-unqualified `D`,
1440
+ returns `&d`; otherwise returns `nullptr`. The returned pointer remains
1441
+ valid as long as there exists a `shared_ptr` instance that owns `d`. It
1442
+ is unspecified whether the pointer remains valid longer than that. This
1443
+ can happen if the implementation doesn’t destroy the deleter until all
1444
  `weak_ptr` instances that share ownership with `p` have been destroyed.
1445
 
1446
  ##### `shared_ptr` I/O <a id="util.smartptr.shared.io">[[util.smartptr.shared.io]]</a>
1447
 
1448
  ``` cpp
 
1469
  // [util.smartptr.weak.const], constructors
1470
  constexpr weak_ptr() noexcept;
1471
  template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
1472
  weak_ptr(weak_ptr const& r) noexcept;
1473
  template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
1474
+ weak_ptr(weak_ptr&& r) noexcept;
1475
+ template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
1476
 
1477
  // [util.smartptr.weak.dest], destructor
1478
  ~weak_ptr();
1479
 
1480
  // [util.smartptr.weak.assign], assignment
1481
  weak_ptr& operator=(weak_ptr const& r) noexcept;
1482
  template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
1483
  template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
1484
+ weak_ptr& operator=(weak_ptr&& r) noexcept;
1485
+ template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
1486
 
1487
  // [util.smartptr.weak.mod], modifiers
1488
  void swap(weak_ptr& r) noexcept;
1489
  void reset() noexcept;
1490
 
1491
  // [util.smartptr.weak.obs], observers
1492
  long use_count() const noexcept;
1493
  bool expired() const noexcept;
1494
  shared_ptr<T> lock() const noexcept;
1495
+ template<class U> bool owner_before(shared_ptr<U> const& b) const;
1496
+ template<class U> bool owner_before(weak_ptr<U> const& b) const;
1497
  };
1498
 
1499
  // [util.smartptr.weak.spec], specialized algorithms
1500
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
1501
  } // namespace std
 
1519
  weak_ptr(const weak_ptr& r) noexcept;
1520
  template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
1521
  template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
1522
  ```
1523
 
1524
+ The second and third constructors shall not participate in overload
1525
+ resolution unless `Y*` is implicitly convertible to `T*`.
1526
 
1527
  *Effects:* If `r` is *empty*, constructs an *empty* `weak_ptr` object;
1528
  otherwise, constructs a `weak_ptr` object that *shares ownership* with
1529
  `r` and stores a copy of the pointer stored in `r`.
1530
 
1531
  *Postconditions:* `use_count() == r.use_count()`.
1532
 
1533
+ ``` cpp
1534
+ weak_ptr(weak_ptr&& r) noexcept;
1535
+ template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
1536
+ ```
1537
+
1538
+ The second constructor shall not participate in overload resolution
1539
+ unless `Y*` is implicitly convertible to `T*`.
1540
+
1541
+ *Effects:* Move-constructs a `weak_ptr` instance from `r`.
1542
+
1543
+ *Postconditions:* `*this` shall contain the old value of `r`. `r` shall
1544
+ be *empty*. `r.use_count() == 0`.
1545
+
1546
  ##### `weak_ptr` destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
1547
 
1548
  ``` cpp
1549
  ~weak_ptr();
1550
  ```
 
1563
  *Effects:* Equivalent to `weak_ptr(r).swap(*this)`.
1564
 
1565
  *Remarks:* The implementation may meet the effects (and the implied
1566
  guarantees) via different means, without creating a temporary.
1567
 
1568
+ *Returns:* `*this`.
1569
+
1570
+ ``` cpp
1571
+ weak_ptr& operator=(weak_ptr&& r) noexcept;
1572
+ template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
1573
+ ```
1574
+
1575
+ *Effects:* Equivalent to `weak_ptr(std::move(r)).swap(*this)`.
1576
+
1577
+ *Returns:* `*this`.
1578
+
1579
  ##### `weak_ptr` modifiers <a id="util.smartptr.weak.mod">[[util.smartptr.weak.mod]]</a>
1580
 
1581
  ``` cpp
1582
  void swap(weak_ptr& r) noexcept;
1583
  ```
 
1611
 
1612
  ``` cpp
1613
  shared_ptr<T> lock() const noexcept;
1614
  ```
1615
 
1616
+ *Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
1617
+ executed atomically.
1618
 
1619
  ``` cpp
1620
+ template<class U> bool owner_before(shared_ptr<U> const& b) const;
1621
+ template<class U> bool owner_before(weak_ptr<U> const& b) const;
1622
  ```
1623
 
1624
  *Returns:* An unspecified value such that
1625
 
1626
  - `x.owner_before(y)` defines a strict weak ordering as defined
 
1636
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
1637
  ```
1638
 
1639
  *Effects:* Equivalent to `a.swap(b)`.
1640
 
1641
+ #### Class template `owner_less` <a id="util.smartptr.ownerless">[[util.smartptr.ownerless]]</a>
1642
 
1643
  The class template `owner_less` allows ownership-based mixed comparisons
1644
  of shared and weak pointers.
1645
 
1646
  ``` cpp
 
1867
  template<class T>
1868
  bool atomic_compare_exchange_weak(
1869
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
1870
  ```
1871
 
1872
+ *Requires:* `p` shall not be null and `v` shall not be null.
1873
 
1874
  *Returns:*
1875
  `atomic_compare_exchange_weak_explicit(p, v, w, memory_order_seq_cst, memory_order_seq_cst)`.
1876
 
1877
  *Throws:* Nothing.
 
1894
  bool atomic_compare_exchange_strong_explicit(
1895
  shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
1896
  memory_order success, memory_order failure);
1897
  ```
1898
 
1899
+ *Requires:* `p` shall not be null and `v` shall not be null.
1900
 
1901
  *Requires:* `failure` shall not be `memory_order_release`,
1902
  `memory_order_acq_rel`, or stronger than `success`.
1903
 
1904
  *Effects:* If `*p` is equivalent to `*v`, assigns `w` to `*p` and has
 
1920
 
1921
  ``` cpp
1922
  template <class T, class D> struct hash<unique_ptr<T, D> >;
1923
  ```
1924
 
1925
+ The template specialization shall meet the requirements of class
1926
+ template `hash` ([[unord.hash]]). For an object `p` of type `UP`, where
1927
+ `UP` is `unique_ptr<T, D>`, `hash<UP>()(p)` shall evaluate to the same
1928
+ value as `hash<typename UP::pointer>()(p.get())`.
1929
+
1930
+ *Requires:* The specialization `hash<typename UP::pointer>` shall be
1931
+ well-formed and well-defined, and shall meet the requirements of class
1932
+ template `hash` ([[unord.hash]]).
1933
 
1934
  ``` cpp
1935
  template <class T> struct hash<shared_ptr<T> >;
1936
  ```
1937
 
1938
+ The template specialization shall meet the requirements of class
1939
+ template `hash` ([[unord.hash]]). For an object `p` of type
1940
  `shared_ptr<T>`, `hash<shared_ptr<T> >()(p)` shall evaluate to the same
1941
  value as `hash<T*>()(p.get())`.
1942