tmp/tmpmxpdx84v/{from.md → to.md}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
| 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 |
|
|
@@ -48,28 +50,25 @@ namespace std {
|
|
| 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;
|
|
@@ -78,13 +77,14 @@ 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
|
| 85 |
-
and stores a copy of the pointer stored
|
|
|
|
| 86 |
|
| 87 |
*Ensures:* `use_count() == r.use_count()`.
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
weak_ptr(weak_ptr&& r) noexcept;
|
|
@@ -93,47 +93,47 @@ template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
|
|
| 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`
|
| 99 |
-
|
| 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;
|
| 127 |
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
| 128 |
```
|
| 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,11 +143,11 @@ void swap(weak_ptr& r) noexcept;
|
|
| 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 |
|
|
@@ -179,11 +179,11 @@ template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
|
|
| 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 |
```
|
|
|
|
| 1 |
+
#### Class template `weak_ptr` <a id="util.smartptr.weak">[[util.smartptr.weak]]</a>
|
| 2 |
+
|
| 3 |
+
##### General <a id="util.smartptr.weak.general">[[util.smartptr.weak.general]]</a>
|
| 4 |
|
| 5 |
The `weak_ptr` class template stores a weak reference to an object that
|
| 6 |
is already managed by a `shared_ptr`. To access the object, a `weak_ptr`
|
| 7 |
can be converted to a `shared_ptr` using the member function `lock`.
|
| 8 |
|
|
|
|
| 50 |
bool owner_before(const weak_ptr<U>& b) const noexcept;
|
| 51 |
};
|
| 52 |
|
| 53 |
template<class T>
|
| 54 |
weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
```
|
| 57 |
|
| 58 |
Specializations of `weak_ptr` shall be *Cpp17CopyConstructible* and
|
| 59 |
*Cpp17CopyAssignable*, allowing their use in standard containers. The
|
| 60 |
template parameter `T` of `weak_ptr` may be an incomplete type.
|
| 61 |
|
| 62 |
+
##### Constructors <a id="util.smartptr.weak.const">[[util.smartptr.weak.const]]</a>
|
| 63 |
|
| 64 |
``` cpp
|
| 65 |
constexpr weak_ptr() noexcept;
|
| 66 |
```
|
| 67 |
|
| 68 |
+
*Effects:* Constructs an empty `weak_ptr` object that stores a null
|
| 69 |
+
pointer value.
|
| 70 |
|
| 71 |
*Ensures:* `use_count() == 0`.
|
| 72 |
|
| 73 |
``` cpp
|
| 74 |
weak_ptr(const weak_ptr& r) noexcept;
|
|
|
|
| 77 |
```
|
| 78 |
|
| 79 |
*Constraints:* For the second and third constructors, `Y*` is compatible
|
| 80 |
with `T*`.
|
| 81 |
|
| 82 |
+
*Effects:* If `r` is empty, constructs an empty `weak_ptr` object that
|
| 83 |
+
stores a null pointer value; otherwise, constructs a `weak_ptr` object
|
| 84 |
+
that shares ownership with `r` and stores a copy of the pointer stored
|
| 85 |
+
in `r`.
|
| 86 |
|
| 87 |
*Ensures:* `use_count() == r.use_count()`.
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
weak_ptr(weak_ptr&& r) noexcept;
|
|
|
|
| 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` contains the old value of `r`. `r` is empty, stores a
|
| 99 |
+
null pointer value, and `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 |
+
*Returns:* `*this`.
|
| 121 |
+
|
| 122 |
*Remarks:* The implementation may meet the effects (and the implied
|
| 123 |
guarantees) via different means, without creating a temporary object.
|
| 124 |
|
|
|
|
|
|
|
| 125 |
``` cpp
|
| 126 |
weak_ptr& operator=(weak_ptr&& r) noexcept;
|
| 127 |
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
|
| 128 |
```
|
| 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 |
|
|
|
|
| 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 |
```
|