tmp/tmpskbascc8/{from.md → to.md}
RENAMED
|
@@ -1,156 +1,151 @@
|
|
| 1 |
-
####
|
| 2 |
|
| 3 |
In the constructor definitions below, enables `shared_from_this` with
|
| 4 |
`p`, for a pointer `p` of type `Y*`, means that if `Y` has an
|
| 5 |
unambiguous and accessible base class that is a specialization of
|
| 6 |
-
`enable_shared_from_this`
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
``` cpp
|
| 11 |
if (p != nullptr && p->weak_this.expired())
|
| 12 |
p->weak_this = shared_ptr<remove_cv_t<Y>>(*this, const_cast<remove_cv_t<Y>*>(p));
|
| 13 |
```
|
| 14 |
|
| 15 |
The assignment to the `weak_this` member is not atomic and conflicts
|
| 16 |
-
with any potentially concurrent access to the same object
|
| 17 |
-
[[intro.multithread]]
|
| 18 |
|
| 19 |
``` cpp
|
| 20 |
constexpr shared_ptr() noexcept;
|
| 21 |
```
|
| 22 |
|
| 23 |
-
*
|
| 24 |
-
|
| 25 |
-
*Postconditions:* `use_count() == 0 && get() == nullptr`.
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
template<class Y> explicit shared_ptr(Y* p);
|
| 29 |
```
|
| 30 |
|
| 31 |
-
*
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
*Effects:* When `T` is not an array type, constructs a `shared_ptr`
|
| 36 |
object that owns the pointer `p`. Otherwise, constructs a `shared_ptr`
|
| 37 |
that owns `p` and a deleter of an unspecified type that calls
|
| 38 |
`delete[] p`. When `T` is not an array type, enables `shared_from_this`
|
| 39 |
with `p`. If an exception is thrown, `delete p` is called when `T` is
|
| 40 |
not an array type, `delete[] p` otherwise.
|
| 41 |
|
| 42 |
-
*
|
| 43 |
|
| 44 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 45 |
resource other than memory could not be obtained.
|
| 46 |
|
| 47 |
-
*Remarks:* When `T` is an array type, this constructor shall not
|
| 48 |
-
participate in overload resolution unless the expression `delete[] p` is
|
| 49 |
-
well-formed and either `T` is `U[N]` and `Y(*)[N]` is convertible to
|
| 50 |
-
`T*`, or `T` is `U[]` and `Y(*)[]` is convertible to `T*`. When `T` is
|
| 51 |
-
not an array type, this constructor shall not participate in overload
|
| 52 |
-
resolution unless the expression `delete p` is well-formed and `Y*` is
|
| 53 |
-
convertible to `T*`.
|
| 54 |
-
|
| 55 |
``` cpp
|
| 56 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 57 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 58 |
template<class D> shared_ptr(nullptr_t p, D d);
|
| 59 |
template<class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 60 |
```
|
| 61 |
|
| 62 |
-
*
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
*Effects:* Constructs a `shared_ptr` object that owns the object `p` and
|
| 68 |
the deleter `d`. When `T` is not an array type, the first and second
|
| 69 |
constructors enable `shared_from_this` with `p`. The second and fourth
|
| 70 |
constructors shall use a copy of `a` to allocate memory for internal
|
| 71 |
use. If an exception is thrown, `d(p)` is called.
|
| 72 |
|
| 73 |
-
*
|
| 74 |
|
| 75 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 76 |
resource other than memory could not be obtained.
|
| 77 |
|
| 78 |
-
*Remarks:* When `T` is an array type, this constructor shall not
|
| 79 |
-
participate in overload resolution unless `is_move_constructible_v<D>`
|
| 80 |
-
is `true`, the expression `d(p)` is well-formed, and either `T` is
|
| 81 |
-
`U[N]` and `Y(*)[N]` is convertible to `T*`, or `T` is `U[]` and
|
| 82 |
-
`Y(*)[]` is convertible to `T*`. When `T` is not an array type, this
|
| 83 |
-
constructor shall not participate in overload resolution unless
|
| 84 |
-
`is_move_constructible_v<D>` is `true`, the expression `d(p)` is
|
| 85 |
-
well-formed, and `Y*` is convertible to `T*`.
|
| 86 |
-
|
| 87 |
``` cpp
|
| 88 |
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
|
|
|
|
| 89 |
```
|
| 90 |
|
| 91 |
*Effects:* Constructs a `shared_ptr` instance that stores `p` and shares
|
| 92 |
-
ownership with `r`.
|
| 93 |
|
| 94 |
-
*
|
|
|
|
| 95 |
|
| 96 |
[*Note 1*: To avoid the possibility of a dangling pointer, the user of
|
| 97 |
-
this constructor
|
| 98 |
ownership group of `r` is destroyed. — *end note*]
|
| 99 |
|
| 100 |
[*Note 2*: This constructor allows creation of an empty `shared_ptr`
|
| 101 |
instance with a non-null stored pointer. — *end note*]
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 105 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 106 |
```
|
| 107 |
|
| 108 |
-
*
|
| 109 |
-
resolution unless `Y*` is compatible with `T*`.
|
| 110 |
|
| 111 |
*Effects:* If `r` is empty, constructs an empty `shared_ptr` object;
|
| 112 |
otherwise, constructs a `shared_ptr` object that shares ownership with
|
| 113 |
`r`.
|
| 114 |
|
| 115 |
-
*
|
| 116 |
|
| 117 |
``` cpp
|
| 118 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 119 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 120 |
```
|
| 121 |
|
| 122 |
-
*
|
| 123 |
-
resolution unless `Y*` is compatible with `T*`.
|
| 124 |
|
| 125 |
*Effects:* Move constructs a `shared_ptr` instance from `r`.
|
| 126 |
|
| 127 |
-
*
|
| 128 |
-
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 132 |
```
|
| 133 |
|
|
|
|
|
|
|
| 134 |
*Effects:* Constructs a `shared_ptr` object that shares ownership with
|
| 135 |
`r` and stores a copy of the pointer stored in `r`. If an exception is
|
| 136 |
thrown, the constructor has no effect.
|
| 137 |
|
| 138 |
-
*
|
| 139 |
|
| 140 |
*Throws:* `bad_weak_ptr` when `r.expired()`.
|
| 141 |
|
| 142 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 143 |
-
unless `Y*` is compatible with `T*`.
|
| 144 |
-
|
| 145 |
``` cpp
|
| 146 |
template<class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 147 |
```
|
| 148 |
|
| 149 |
-
*
|
| 150 |
-
|
| 151 |
-
convertible to `element_type*`.
|
| 152 |
|
| 153 |
*Effects:* If `r.get() == nullptr`, equivalent to `shared_ptr()`.
|
| 154 |
Otherwise, if `D` is not a reference type, equivalent to
|
| 155 |
`shared_ptr(r.release(), r.get_deleter())`. Otherwise, equivalent to
|
| 156 |
`shared_ptr(r.release(), ref(r.get_deleter()))`. If an exception is
|
|
|
|
| 1 |
+
#### Constructors <a id="util.smartptr.shared.const">[[util.smartptr.shared.const]]</a>
|
| 2 |
|
| 3 |
In the constructor definitions below, enables `shared_from_this` with
|
| 4 |
`p`, for a pointer `p` of type `Y*`, means that if `Y` has an
|
| 5 |
unambiguous and accessible base class that is a specialization of
|
| 6 |
+
`enable_shared_from_this` [[util.smartptr.enab]], then `remove_cv_t<Y>*`
|
| 7 |
+
shall be implicitly convertible to `T*` and the constructor evaluates
|
| 8 |
+
the statement:
|
| 9 |
|
| 10 |
``` cpp
|
| 11 |
if (p != nullptr && p->weak_this.expired())
|
| 12 |
p->weak_this = shared_ptr<remove_cv_t<Y>>(*this, const_cast<remove_cv_t<Y>*>(p));
|
| 13 |
```
|
| 14 |
|
| 15 |
The assignment to the `weak_this` member is not atomic and conflicts
|
| 16 |
+
with any potentially concurrent access to the same object
|
| 17 |
+
[[intro.multithread]].
|
| 18 |
|
| 19 |
``` cpp
|
| 20 |
constexpr shared_ptr() noexcept;
|
| 21 |
```
|
| 22 |
|
| 23 |
+
*Ensures:* `use_count() == 0 && get() == nullptr`.
|
|
|
|
|
|
|
| 24 |
|
| 25 |
``` cpp
|
| 26 |
template<class Y> explicit shared_ptr(Y* p);
|
| 27 |
```
|
| 28 |
|
| 29 |
+
*Mandates:* `Y` is a complete type.
|
| 30 |
+
|
| 31 |
+
*Constraints:* When `T` is an array type, the expression `delete[] p` is
|
| 32 |
+
well-formed and either `T` is `U[N]` and `Y(*)[N]` is convertible to
|
| 33 |
+
`T*`, or `T` is `U[]` and `Y(*)[]` is convertible to `T*`. When `T` is
|
| 34 |
+
not an array type, the expression `delete p` is well-formed and `Y*` is
|
| 35 |
+
convertible to `T*`.
|
| 36 |
+
|
| 37 |
+
*Preconditions:* The expression `delete[] p`, when `T` is an array type,
|
| 38 |
+
or `delete p`, when `T` is not an array type, has well-defined behavior,
|
| 39 |
+
and does not throw exceptions.
|
| 40 |
|
| 41 |
*Effects:* When `T` is not an array type, constructs a `shared_ptr`
|
| 42 |
object that owns the pointer `p`. Otherwise, constructs a `shared_ptr`
|
| 43 |
that owns `p` and a deleter of an unspecified type that calls
|
| 44 |
`delete[] p`. When `T` is not an array type, enables `shared_from_this`
|
| 45 |
with `p`. If an exception is thrown, `delete p` is called when `T` is
|
| 46 |
not an array type, `delete[] p` otherwise.
|
| 47 |
|
| 48 |
+
*Ensures:* `use_count() == 1 && get() == p`.
|
| 49 |
|
| 50 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 51 |
resource other than memory could not be obtained.
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
``` cpp
|
| 54 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 55 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 56 |
template<class D> shared_ptr(nullptr_t p, D d);
|
| 57 |
template<class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 58 |
```
|
| 59 |
|
| 60 |
+
*Constraints:* `is_move_constructible_v<D>` is `true`, and `d(p)` is a
|
| 61 |
+
well-formed expression. For the first two overloads:
|
| 62 |
+
|
| 63 |
+
- If `T` is an array type, then either `T` is `U[N]` and `Y(*)[N]` is
|
| 64 |
+
convertible to `T*`, or `T` is `U[]` and `Y(*)[]` is convertible to
|
| 65 |
+
`T*`.
|
| 66 |
+
- If `T` is not an array type, then `Y*` is convertible to `T*`.
|
| 67 |
+
|
| 68 |
+
*Preconditions:* Construction of `d` and a deleter of type `D`
|
| 69 |
+
initialized with `std::move(d)` do not throw exceptions. The expression
|
| 70 |
+
`d(p)` has well-defined behavior and does not throw exceptions. `A`
|
| 71 |
+
meets the *Cpp17Allocator* requirements ([[cpp17.allocator]]).
|
| 72 |
|
| 73 |
*Effects:* Constructs a `shared_ptr` object that owns the object `p` and
|
| 74 |
the deleter `d`. When `T` is not an array type, the first and second
|
| 75 |
constructors enable `shared_from_this` with `p`. The second and fourth
|
| 76 |
constructors shall use a copy of `a` to allocate memory for internal
|
| 77 |
use. If an exception is thrown, `d(p)` is called.
|
| 78 |
|
| 79 |
+
*Ensures:* `use_count() == 1 && get() == p`.
|
| 80 |
|
| 81 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 82 |
resource other than memory could not be obtained.
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
``` cpp
|
| 85 |
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
|
| 86 |
+
template<class Y> shared_ptr(shared_ptr<Y>&& r, element_type* p) noexcept;
|
| 87 |
```
|
| 88 |
|
| 89 |
*Effects:* Constructs a `shared_ptr` instance that stores `p` and shares
|
| 90 |
+
ownership with the initial value of `r`.
|
| 91 |
|
| 92 |
+
*Ensures:* `get() == p`. For the second overload, `r` is empty and
|
| 93 |
+
`r.get() == nullptr`.
|
| 94 |
|
| 95 |
[*Note 1*: To avoid the possibility of a dangling pointer, the user of
|
| 96 |
+
this constructor should ensure that `p` remains valid at least until the
|
| 97 |
ownership group of `r` is destroyed. — *end note*]
|
| 98 |
|
| 99 |
[*Note 2*: This constructor allows creation of an empty `shared_ptr`
|
| 100 |
instance with a non-null stored pointer. — *end note*]
|
| 101 |
|
| 102 |
``` cpp
|
| 103 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 104 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 105 |
```
|
| 106 |
|
| 107 |
+
*Constraints:* For the second constructor, `Y*` is compatible with `T*`.
|
|
|
|
| 108 |
|
| 109 |
*Effects:* If `r` is empty, constructs an empty `shared_ptr` object;
|
| 110 |
otherwise, constructs a `shared_ptr` object that shares ownership with
|
| 111 |
`r`.
|
| 112 |
|
| 113 |
+
*Ensures:* `get() == r.get() && use_count() == r.use_count()`.
|
| 114 |
|
| 115 |
``` cpp
|
| 116 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 117 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 118 |
```
|
| 119 |
|
| 120 |
+
*Constraints:* For the second constructor, `Y*` is compatible with `T*`.
|
|
|
|
| 121 |
|
| 122 |
*Effects:* Move constructs a `shared_ptr` instance from `r`.
|
| 123 |
|
| 124 |
+
*Ensures:* `*this` shall contain the old value of `r`. `r` shall be
|
| 125 |
+
empty. `r.get() == nullptr`.
|
| 126 |
|
| 127 |
``` cpp
|
| 128 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 129 |
```
|
| 130 |
|
| 131 |
+
*Constraints:* `Y*` is compatible with `T*`.
|
| 132 |
+
|
| 133 |
*Effects:* Constructs a `shared_ptr` object that shares ownership with
|
| 134 |
`r` and stores a copy of the pointer stored in `r`. If an exception is
|
| 135 |
thrown, the constructor has no effect.
|
| 136 |
|
| 137 |
+
*Ensures:* `use_count() == r.use_count()`.
|
| 138 |
|
| 139 |
*Throws:* `bad_weak_ptr` when `r.expired()`.
|
| 140 |
|
|
|
|
|
|
|
|
|
|
| 141 |
``` cpp
|
| 142 |
template<class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 143 |
```
|
| 144 |
|
| 145 |
+
*Constraints:* `Y*` is compatible with `T*` and
|
| 146 |
+
`unique_ptr<Y, D>::pointer` is convertible to `element_type*`.
|
|
|
|
| 147 |
|
| 148 |
*Effects:* If `r.get() == nullptr`, equivalent to `shared_ptr()`.
|
| 149 |
Otherwise, if `D` is not a reference type, equivalent to
|
| 150 |
`shared_ptr(r.release(), r.get_deleter())`. Otherwise, equivalent to
|
| 151 |
`shared_ptr(r.release(), ref(r.get_deleter()))`. If an exception is
|