tmp/tmp0t85necg/{from.md → to.md}
RENAMED
|
@@ -1,138 +1,158 @@
|
|
| 1 |
##### `shared_ptr` constructors <a id="util.smartptr.shared.const">[[util.smartptr.shared.const]]</a>
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
``` cpp
|
| 4 |
constexpr shared_ptr() noexcept;
|
| 5 |
```
|
| 6 |
|
| 7 |
-
*Effects:* Constructs an
|
| 8 |
|
| 9 |
*Postconditions:* `use_count() == 0 && get() == nullptr`.
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
template<class Y> explicit shared_ptr(Y* p);
|
| 13 |
```
|
| 14 |
|
| 15 |
-
*Requires:* `
|
| 16 |
-
|
| 17 |
-
defined behavior, and shall not throw exceptions.
|
| 18 |
|
| 19 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 22 |
|
| 23 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 24 |
resource other than memory could not be obtained.
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
``` cpp
|
| 29 |
template<class Y, class D> shared_ptr(Y* p, D d);
|
| 30 |
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
| 31 |
template <class D> shared_ptr(nullptr_t p, D d);
|
| 32 |
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
| 33 |
```
|
| 34 |
|
| 35 |
-
*Requires:* `
|
| 36 |
-
`
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
an allocator ([[allocator.requirements]]). The copy constructor and
|
| 40 |
-
destructor of `A` shall not throw exceptions.
|
| 41 |
|
| 42 |
-
*Effects:* Constructs a `shared_ptr` object that
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 47 |
|
| 48 |
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 49 |
resource other than memory could not be obtained.
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
-
template<class Y> shared_ptr(const shared_ptr<Y>& r,
|
| 55 |
```
|
| 56 |
|
| 57 |
-
*Effects:* Constructs a `shared_ptr` instance that stores `p` and
|
| 58 |
-
|
| 59 |
|
| 60 |
-
*Postconditions:* `get() == p && use_count() == r.use_count()`
|
| 61 |
|
| 62 |
-
To avoid the possibility of a dangling pointer, the user of
|
| 63 |
-
constructor must ensure that `p` remains valid at least until the
|
| 64 |
-
ownership group of `r` is destroyed.
|
| 65 |
|
| 66 |
-
This constructor allows creation of an
|
| 67 |
-
with a non-null stored pointer.
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
shared_ptr(const shared_ptr& r) noexcept;
|
| 71 |
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
| 72 |
```
|
| 73 |
|
| 74 |
-
The second constructor shall not participate in overload
|
| 75 |
-
unless `Y*` is
|
| 76 |
|
| 77 |
-
*Effects:* If `r` is
|
| 78 |
-
otherwise, constructs a `shared_ptr` object that
|
| 79 |
`r`.
|
| 80 |
|
| 81 |
*Postconditions:* `get() == r.get() && use_count() == r.use_count()`.
|
| 82 |
|
| 83 |
``` cpp
|
| 84 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 85 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 86 |
```
|
| 87 |
|
| 88 |
-
The second constructor shall not participate in overload
|
| 89 |
-
unless `Y*` is
|
| 90 |
|
| 91 |
-
*Effects:* Move
|
| 92 |
|
| 93 |
*Postconditions:* `*this` shall contain the old value of `r`. `r` shall
|
| 94 |
-
be
|
| 95 |
|
| 96 |
``` cpp
|
| 97 |
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
| 98 |
```
|
| 99 |
|
| 100 |
-
*
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
`r` and stores a copy of the pointer stored in `r`.
|
| 104 |
|
| 105 |
*Postconditions:* `use_count() == r.use_count()`.
|
| 106 |
|
| 107 |
*Throws:* `bad_weak_ptr` when `r.expired()`.
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
``` cpp
|
| 112 |
-
template<class Y> shared_ptr(auto_ptr<Y>&& r);
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
*Requires:* `r.release()` shall be convertible to `T*`. `Y` shall be a
|
| 116 |
-
complete type. The expression `delete r.release()` shall be well formed,
|
| 117 |
-
shall have well defined behavior, and shall not throw exceptions.
|
| 118 |
-
|
| 119 |
-
*Effects:* Constructs a `shared_ptr` object that stores and *owns*
|
| 120 |
-
`r.release()`.
|
| 121 |
-
|
| 122 |
-
*Postconditions:* `use_count() == 1` `&&` `r.get() == nullptr`.
|
| 123 |
-
|
| 124 |
-
*Throws:* `bad_alloc`, or an *implementation-defined* exception when a
|
| 125 |
-
resource other than memory could not be obtained.
|
| 126 |
-
|
| 127 |
-
If an exception is thrown, the constructor has no effect.
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
| 131 |
```
|
| 132 |
|
| 133 |
-
*
|
| 134 |
-
`
|
| 135 |
-
|
| 136 |
|
| 137 |
-
If
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
|
|
|
| 1 |
##### `shared_ptr` 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
|
| 7 |
+
`remove_cv_t<Y>*` shall be implicitly convertible to `T*` and the
|
| 8 |
+
constructor evaluates 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 |
+
*Effects:* Constructs an empty `shared_ptr` object.
|
| 24 |
|
| 25 |
*Postconditions:* `use_count() == 0 && get() == nullptr`.
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
template<class Y> explicit shared_ptr(Y* p);
|
| 29 |
```
|
| 30 |
|
| 31 |
+
*Requires:* `Y` shall be a complete type. The expression `delete[] p`,
|
| 32 |
+
when `T` is an array type, or `delete p`, when `T` is not an array type,
|
| 33 |
+
shall have well-defined behavior, and shall not throw exceptions.
|
| 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 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 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 |
+
*Requires:* Construction of `d` and a deleter of type `D` initialized
|
| 63 |
+
with `std::move(d)` shall not throw exceptions. The expression `d(p)`
|
| 64 |
+
shall have well-defined behavior and shall not throw exceptions. `A`
|
| 65 |
+
shall be an allocator ([[allocator.requirements]]).
|
|
|
|
|
|
|
| 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 |
*Postconditions:* `use_count() == 1 && get() == p`.
|
| 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 |
+
*Postconditions:* `get() == p && use_count() == r.use_count()`.
|
| 95 |
|
| 96 |
+
[*Note 1*: To avoid the possibility of a dangling pointer, the user of
|
| 97 |
+
this constructor must ensure that `p` remains valid at least until the
|
| 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 |
+
*Remarks:* The second constructor shall not participate in overload
|
| 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 |
*Postconditions:* `get() == r.get() && use_count() == r.use_count()`.
|
| 116 |
|
| 117 |
``` cpp
|
| 118 |
shared_ptr(shared_ptr&& r) noexcept;
|
| 119 |
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
| 120 |
```
|
| 121 |
|
| 122 |
+
*Remarks:* The second constructor shall not participate in overload
|
| 123 |
+
resolution unless `Y*` is compatible with `T*`.
|
| 124 |
|
| 125 |
+
*Effects:* Move constructs a `shared_ptr` instance from `r`.
|
| 126 |
|
| 127 |
*Postconditions:* `*this` shall contain the old value of `r`. `r` shall
|
| 128 |
+
be empty. `r.get() == nullptr`.
|
| 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 |
*Postconditions:* `use_count() == r.use_count()`.
|
| 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 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 150 |
+
unless `Y*` is compatible with `T*` and `unique_ptr<Y, D>::pointer` is
|
| 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
|
| 157 |
+
thrown, the constructor has no effect.
|
| 158 |
|