tmp/tmp7njbabzj/{from.md → to.md}
RENAMED
|
@@ -1,118 +1,126 @@
|
|
| 1 |
-
###
|
| 2 |
|
| 3 |
The `weak_ptr` class template stores a weak reference to an object that
|
| 4 |
is already managed by a `shared_ptr`. To access the object, a `weak_ptr`
|
| 5 |
can be converted to a `shared_ptr` using the member function `lock`.
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
namespace std {
|
| 9 |
template<class T> class weak_ptr {
|
| 10 |
public:
|
| 11 |
-
using element_type = T;
|
| 12 |
|
| 13 |
// [util.smartptr.weak.const], constructors
|
| 14 |
constexpr weak_ptr() noexcept;
|
| 15 |
-
template<class Y>
|
|
|
|
| 16 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 17 |
-
template<class Y>
|
|
|
|
| 18 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 19 |
-
template<class Y>
|
|
|
|
| 20 |
|
| 21 |
// [util.smartptr.weak.dest], destructor
|
| 22 |
~weak_ptr();
|
| 23 |
|
| 24 |
// [util.smartptr.weak.assign], assignment
|
| 25 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 26 |
-
template<class Y>
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 29 |
-
template<class Y>
|
|
|
|
| 30 |
|
| 31 |
// [util.smartptr.weak.mod], modifiers
|
| 32 |
void swap(weak_ptr& r) noexcept;
|
| 33 |
void reset() noexcept;
|
| 34 |
|
| 35 |
// [util.smartptr.weak.obs], observers
|
| 36 |
long use_count() const noexcept;
|
| 37 |
bool expired() const noexcept;
|
| 38 |
shared_ptr<T> lock() const noexcept;
|
| 39 |
-
template<class U>
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
};
|
| 42 |
|
| 43 |
-
template<class T>
|
| 44 |
-
|
| 45 |
|
| 46 |
// [util.smartptr.weak.spec], specialized algorithms
|
| 47 |
-
template<class T>
|
|
|
|
| 48 |
}
|
| 49 |
```
|
| 50 |
|
| 51 |
-
Specializations of `weak_ptr` shall be
|
| 52 |
-
|
| 53 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
| 54 |
|
| 55 |
-
####
|
| 56 |
|
| 57 |
``` cpp
|
| 58 |
constexpr weak_ptr() noexcept;
|
| 59 |
```
|
| 60 |
|
| 61 |
*Effects:* Constructs an empty `weak_ptr` object.
|
| 62 |
|
| 63 |
-
*
|
| 64 |
|
| 65 |
``` cpp
|
| 66 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 67 |
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 68 |
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 69 |
```
|
| 70 |
|
| 71 |
-
*
|
| 72 |
-
|
| 73 |
|
| 74 |
*Effects:* If `r` is empty, constructs an empty `weak_ptr` object;
|
| 75 |
otherwise, constructs a `weak_ptr` object that shares ownership with `r`
|
| 76 |
and stores a copy of the pointer stored in `r`.
|
| 77 |
|
| 78 |
-
*
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 82 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 83 |
```
|
| 84 |
|
| 85 |
-
*
|
| 86 |
-
resolution unless `Y*` is compatible with `T*`.
|
| 87 |
|
| 88 |
*Effects:* Move constructs a `weak_ptr` instance from `r`.
|
| 89 |
|
| 90 |
-
*
|
| 91 |
-
|
| 92 |
|
| 93 |
-
####
|
| 94 |
|
| 95 |
``` cpp
|
| 96 |
~weak_ptr();
|
| 97 |
```
|
| 98 |
|
| 99 |
*Effects:* Destroys this `weak_ptr` object but has no effect on the
|
| 100 |
object its stored pointer points to.
|
| 101 |
|
| 102 |
-
####
|
| 103 |
|
| 104 |
``` cpp
|
| 105 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 106 |
template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 107 |
template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 108 |
```
|
| 109 |
|
| 110 |
*Effects:* Equivalent to `weak_ptr(r).swap(*this)`.
|
| 111 |
|
| 112 |
*Remarks:* The implementation may meet the effects (and the implied
|
| 113 |
-
guarantees) via different means, without creating a temporary.
|
| 114 |
|
| 115 |
*Returns:* `*this`.
|
| 116 |
|
| 117 |
``` cpp
|
| 118 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
|
@@ -121,11 +129,11 @@ template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
|
| 121 |
|
| 122 |
*Effects:* Equivalent to `weak_ptr(std::move(r)).swap(*this)`.
|
| 123 |
|
| 124 |
*Returns:* `*this`.
|
| 125 |
|
| 126 |
-
####
|
| 127 |
|
| 128 |
``` cpp
|
| 129 |
void swap(weak_ptr& r) noexcept;
|
| 130 |
```
|
| 131 |
|
|
@@ -135,11 +143,11 @@ void swap(weak_ptr& r) noexcept;
|
|
| 135 |
void reset() noexcept;
|
| 136 |
```
|
| 137 |
|
| 138 |
*Effects:* Equivalent to `weak_ptr().swap(*this)`.
|
| 139 |
|
| 140 |
-
####
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
long use_count() const noexcept;
|
| 144 |
```
|
| 145 |
|
|
@@ -158,12 +166,12 @@ shared_ptr<T> lock() const noexcept;
|
|
| 158 |
|
| 159 |
*Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
|
| 160 |
executed atomically.
|
| 161 |
|
| 162 |
``` cpp
|
| 163 |
-
template<class U> bool owner_before(const shared_ptr<U>& b) const;
|
| 164 |
-
template<class U> bool owner_before(const weak_ptr<U>& b) const;
|
| 165 |
```
|
| 166 |
|
| 167 |
*Returns:* An unspecified value such that
|
| 168 |
|
| 169 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
@@ -171,11 +179,11 @@ template<class U> bool owner_before(const weak_ptr<U>& b) const;
|
|
| 171 |
- under the equivalence relation defined by `owner_before`,
|
| 172 |
`!a.owner_before(b) && !b.owner_before(a)`, two `shared_ptr` or
|
| 173 |
`weak_ptr` instances are equivalent if and only if they share
|
| 174 |
ownership or are both empty.
|
| 175 |
|
| 176 |
-
####
|
| 177 |
|
| 178 |
``` cpp
|
| 179 |
template<class T>
|
| 180 |
void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 181 |
```
|
|
|
|
| 1 |
+
### Class template `weak_ptr` <a id="util.smartptr.weak">[[util.smartptr.weak]]</a>
|
| 2 |
|
| 3 |
The `weak_ptr` class template stores a weak reference to an object that
|
| 4 |
is already managed by a `shared_ptr`. To access the object, a `weak_ptr`
|
| 5 |
can be converted to a `shared_ptr` using the member function `lock`.
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
namespace std {
|
| 9 |
template<class T> class weak_ptr {
|
| 10 |
public:
|
| 11 |
+
using element_type = remove_extent_t<T>;
|
| 12 |
|
| 13 |
// [util.smartptr.weak.const], constructors
|
| 14 |
constexpr weak_ptr() noexcept;
|
| 15 |
+
template<class Y>
|
| 16 |
+
weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 17 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 18 |
+
template<class Y>
|
| 19 |
+
weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 20 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 21 |
+
template<class Y>
|
| 22 |
+
weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 23 |
|
| 24 |
// [util.smartptr.weak.dest], destructor
|
| 25 |
~weak_ptr();
|
| 26 |
|
| 27 |
// [util.smartptr.weak.assign], assignment
|
| 28 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 29 |
+
template<class Y>
|
| 30 |
+
weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 31 |
+
template<class Y>
|
| 32 |
+
weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 33 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 34 |
+
template<class Y>
|
| 35 |
+
weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
| 36 |
|
| 37 |
// [util.smartptr.weak.mod], modifiers
|
| 38 |
void swap(weak_ptr& r) noexcept;
|
| 39 |
void reset() noexcept;
|
| 40 |
|
| 41 |
// [util.smartptr.weak.obs], observers
|
| 42 |
long use_count() const noexcept;
|
| 43 |
bool expired() const noexcept;
|
| 44 |
shared_ptr<T> lock() const noexcept;
|
| 45 |
+
template<class U>
|
| 46 |
+
bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 47 |
+
template<class U>
|
| 48 |
+
bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 49 |
};
|
| 50 |
|
| 51 |
+
template<class T>
|
| 52 |
+
weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
|
| 53 |
|
| 54 |
// [util.smartptr.weak.spec], specialized algorithms
|
| 55 |
+
template<class T>
|
| 56 |
+
void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 57 |
}
|
| 58 |
```
|
| 59 |
|
| 60 |
+
Specializations of `weak_ptr` shall be *Cpp17CopyConstructible* and
|
| 61 |
+
*Cpp17CopyAssignable*, allowing their use in standard containers. The
|
| 62 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
| 63 |
|
| 64 |
+
#### Constructors <a id="util.smartptr.weak.const">[[util.smartptr.weak.const]]</a>
|
| 65 |
|
| 66 |
``` cpp
|
| 67 |
constexpr weak_ptr() noexcept;
|
| 68 |
```
|
| 69 |
|
| 70 |
*Effects:* Constructs an empty `weak_ptr` object.
|
| 71 |
|
| 72 |
+
*Ensures:* `use_count() == 0`.
|
| 73 |
|
| 74 |
``` cpp
|
| 75 |
weak_ptr(const weak_ptr& r) noexcept;
|
| 76 |
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
|
| 77 |
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
|
| 78 |
```
|
| 79 |
|
| 80 |
+
*Constraints:* For the second and third constructors, `Y*` is compatible
|
| 81 |
+
with `T*`.
|
| 82 |
|
| 83 |
*Effects:* If `r` is empty, constructs an empty `weak_ptr` object;
|
| 84 |
otherwise, constructs a `weak_ptr` object that shares ownership with `r`
|
| 85 |
and stores a copy of the pointer stored in `r`.
|
| 86 |
|
| 87 |
+
*Ensures:* `use_count() == r.use_count()`.
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
weak_ptr(weak_ptr&& r) noexcept;
|
| 91 |
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
| 92 |
```
|
| 93 |
|
| 94 |
+
*Constraints:* For the second constructor, `Y*` is compatible with `T*`.
|
|
|
|
| 95 |
|
| 96 |
*Effects:* Move constructs a `weak_ptr` instance from `r`.
|
| 97 |
|
| 98 |
+
*Ensures:* `*this` shall contain the old value of `r`. `r` shall be
|
| 99 |
+
empty. `r.use_count() == 0`.
|
| 100 |
|
| 101 |
+
#### Destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
~weak_ptr();
|
| 105 |
```
|
| 106 |
|
| 107 |
*Effects:* Destroys this `weak_ptr` object but has no effect on the
|
| 108 |
object its stored pointer points to.
|
| 109 |
|
| 110 |
+
#### Assignment <a id="util.smartptr.weak.assign">[[util.smartptr.weak.assign]]</a>
|
| 111 |
|
| 112 |
``` cpp
|
| 113 |
weak_ptr& operator=(const weak_ptr& r) noexcept;
|
| 114 |
template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
|
| 115 |
template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
| 116 |
```
|
| 117 |
|
| 118 |
*Effects:* Equivalent to `weak_ptr(r).swap(*this)`.
|
| 119 |
|
| 120 |
*Remarks:* The implementation may meet the effects (and the implied
|
| 121 |
+
guarantees) via different means, without creating a temporary object.
|
| 122 |
|
| 123 |
*Returns:* `*this`.
|
| 124 |
|
| 125 |
``` cpp
|
| 126 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
|
|
|
| 129 |
|
| 130 |
*Effects:* Equivalent to `weak_ptr(std::move(r)).swap(*this)`.
|
| 131 |
|
| 132 |
*Returns:* `*this`.
|
| 133 |
|
| 134 |
+
#### Modifiers <a id="util.smartptr.weak.mod">[[util.smartptr.weak.mod]]</a>
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
void swap(weak_ptr& r) noexcept;
|
| 138 |
```
|
| 139 |
|
|
|
|
| 143 |
void reset() noexcept;
|
| 144 |
```
|
| 145 |
|
| 146 |
*Effects:* Equivalent to `weak_ptr().swap(*this)`.
|
| 147 |
|
| 148 |
+
#### Observers <a id="util.smartptr.weak.obs">[[util.smartptr.weak.obs]]</a>
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
long use_count() const noexcept;
|
| 152 |
```
|
| 153 |
|
|
|
|
| 166 |
|
| 167 |
*Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
|
| 168 |
executed atomically.
|
| 169 |
|
| 170 |
``` cpp
|
| 171 |
+
template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
|
| 172 |
+
template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 173 |
```
|
| 174 |
|
| 175 |
*Returns:* An unspecified value such that
|
| 176 |
|
| 177 |
- `x.owner_before(y)` defines a strict weak ordering as defined
|
|
|
|
| 179 |
- under the equivalence relation defined by `owner_before`,
|
| 180 |
`!a.owner_before(b) && !b.owner_before(a)`, two `shared_ptr` or
|
| 181 |
`weak_ptr` instances are equivalent if and only if they share
|
| 182 |
ownership or are both empty.
|
| 183 |
|
| 184 |
+
#### Specialized algorithms <a id="util.smartptr.weak.spec">[[util.smartptr.weak.spec]]</a>
|
| 185 |
|
| 186 |
``` cpp
|
| 187 |
template<class T>
|
| 188 |
void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
| 189 |
```
|