tmp/tmpuzkue9ru/{from.md → to.md}
RENAMED
|
@@ -2,26 +2,23 @@
|
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
template <class T, class D = default_delete<T>> class unique_ptr {
|
| 6 |
public:
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
// [unique.ptr.single.ctor], constructors
|
| 12 |
constexpr unique_ptr() noexcept;
|
| 13 |
explicit unique_ptr(pointer p) noexcept;
|
| 14 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 15 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 16 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 17 |
-
constexpr unique_ptr(nullptr_t) noexcept
|
| 18 |
-
: unique_ptr() { }
|
| 19 |
template <class U, class E>
|
| 20 |
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 21 |
-
template <class U>
|
| 22 |
-
unique_ptr(auto_ptr<U>&& u) noexcept;
|
| 23 |
|
| 24 |
// [unique.ptr.single.dtor], destructor
|
| 25 |
~unique_ptr();
|
| 26 |
|
| 27 |
// [unique.ptr.single.asgn], assignment
|
|
@@ -35,11 +32,11 @@ namespace std {
|
|
| 35 |
pointer get() const noexcept;
|
| 36 |
deleter_type& get_deleter() noexcept;
|
| 37 |
const deleter_type& get_deleter() const noexcept;
|
| 38 |
explicit operator bool() const noexcept;
|
| 39 |
|
| 40 |
-
// [unique.ptr.single.modifiers] modifiers
|
| 41 |
pointer release() noexcept;
|
| 42 |
void reset(pointer p = pointer()) noexcept;
|
| 43 |
void swap(unique_ptr& u) noexcept;
|
| 44 |
|
| 45 |
// disable copy from lvalue
|
|
@@ -49,149 +46,148 @@ namespace std {
|
|
| 49 |
}
|
| 50 |
```
|
| 51 |
|
| 52 |
The default type for the template parameter `D` is `default_delete`. A
|
| 53 |
client-supplied template argument `D` shall be a function object type (
|
| 54 |
-
[[function.objects]]), lvalue
|
| 55 |
to function object type for which, given a value `d` of type `D` and a
|
| 56 |
value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
|
| 57 |
is valid and has the effect of disposing of the pointer as appropriate
|
| 58 |
for that deleter.
|
| 59 |
|
| 60 |
If the deleter’s type `D` is not a reference type, `D` shall satisfy the
|
| 61 |
-
requirements of `Destructible` (Table [[destructible]]).
|
| 62 |
|
| 63 |
-
If the
|
|
|
|
| 64 |
D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
|
| 65 |
-
Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
|
| 66 |
-
type `unique_ptr<T,
|
| 67 |
D>::pointer` shall satisfy the requirements of `NullablePointer` (
|
| 68 |
[[nullablepointer.requirements]]).
|
| 69 |
|
| 70 |
-
Given an allocator type `X` ([[allocator.requirements]])
|
| 71 |
-
`A` be a synonym for `allocator_traits<X>`, the types
|
| 72 |
-
`A::
|
| 73 |
-
be used as
|
|
|
|
| 74 |
|
| 75 |
##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
constexpr unique_ptr() noexcept;
|
|
|
|
| 79 |
```
|
| 80 |
|
| 81 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 82 |
-
(Table [[defaultconstructible]]), and that construction shall not
|
| 83 |
-
an exception.
|
| 84 |
|
| 85 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 86 |
value-initializing the stored pointer and the stored deleter.
|
| 87 |
|
| 88 |
*Postconditions:* `get() == nullptr`. `get_deleter()` returns a
|
| 89 |
reference to the stored deleter.
|
| 90 |
|
| 91 |
-
*Remarks:* If
|
| 92 |
-
|
|
|
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
explicit unique_ptr(pointer p) noexcept;
|
| 96 |
```
|
| 97 |
|
| 98 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 99 |
-
(Table [[defaultconstructible]]), and that construction shall not
|
| 100 |
-
an exception.
|
| 101 |
|
| 102 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 103 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 104 |
|
| 105 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 106 |
the stored deleter.
|
| 107 |
|
| 108 |
-
*Remarks:* If
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 113 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 114 |
```
|
| 115 |
|
| 116 |
The signature of these constructors depends upon whether `D` is a
|
| 117 |
-
reference type. If `D` is non-reference type `A`, then the signatures
|
| 118 |
are:
|
| 119 |
|
| 120 |
``` cpp
|
| 121 |
-
unique_ptr(pointer p, const A& d);
|
| 122 |
-
unique_ptr(pointer p, A&& d);
|
| 123 |
```
|
| 124 |
|
| 125 |
-
If `D` is an lvalue
|
| 126 |
|
| 127 |
``` cpp
|
| 128 |
-
unique_ptr(pointer p, A& d);
|
| 129 |
-
unique_ptr(pointer p, A&& d);
|
| 130 |
```
|
| 131 |
|
| 132 |
-
If `D` is an lvalue
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
-
unique_ptr(pointer p, const A& d);
|
| 136 |
-
unique_ptr(pointer p, const A&& d);
|
| 137 |
```
|
| 138 |
|
| 139 |
-
*Requires:*
|
| 140 |
-
|
| 141 |
-
- If `D` is not an lvalue-reference type then
|
| 142 |
-
- If `d` is an lvalue or `const` rvalue then the first constructor of
|
| 143 |
-
this pair will be selected. `D` shall satisfy the requirements of
|
| 144 |
-
`CopyConstructible` (Table [[copyconstructible]]), and the copy
|
| 145 |
-
constructor of `D` shall not throw an exception. This `unique_ptr`
|
| 146 |
-
will hold a copy of `d`.
|
| 147 |
-
- Otherwise, `d` is a non-const rvalue and the second constructor of
|
| 148 |
-
this pair will be selected. `D` shall satisfy the requirements of
|
| 149 |
-
`MoveConstructible` (Table [[moveconstructible]]), and the move
|
| 150 |
-
constructor of `D` shall not throw an exception. This `unique_ptr`
|
| 151 |
-
will hold a value move constructed from `d`.
|
| 152 |
-
- Otherwise `D` is an lvalue-reference type. `d` shall be
|
| 153 |
-
reference-compatible with one of the constructors. If `d` is an
|
| 154 |
-
rvalue, it will bind to the second constructor of this pair and the
|
| 155 |
-
program is ill-formed. The diagnostic could be implemented using a
|
| 156 |
-
`static_assert` which assures that `D` is not a reference type. Else
|
| 157 |
-
`d` is an lvalue and will bind to the first constructor of this pair.
|
| 158 |
-
The type which `D` references need not be `CopyConstructible` nor
|
| 159 |
-
`MoveConstructible`. This `unique_ptr` will hold a `D` which refers to
|
| 160 |
-
the lvalue `d`. `D` may not be an rvalue-reference type.
|
| 161 |
-
|
| 162 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 163 |
-
the stored pointer with `p` and initializing the deleter
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 167 |
the stored deleter. If `D` is a reference type then `get_deleter()`
|
| 168 |
returns a reference to the lvalue `d`.
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
``` cpp
|
| 171 |
D d;
|
| 172 |
unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
|
| 173 |
unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
|
| 174 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 175 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 176 |
// with reference deleter type
|
| 177 |
```
|
| 178 |
|
|
|
|
|
|
|
| 179 |
``` cpp
|
| 180 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 181 |
```
|
| 182 |
|
| 183 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 184 |
-
requirements of `MoveConstructible` (Table [[moveconstructible]]).
|
| 185 |
Construction of the deleter from an rvalue of type `D` shall not throw
|
| 186 |
an exception.
|
| 187 |
|
| 188 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 189 |
to `*this`. If `D` is a reference type, this deleter is copy constructed
|
| 190 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 191 |
-
`u`’s deleter.
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
|
| 194 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 195 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 196 |
that was constructed from `u.get_deleter()`. If `D` is a reference type
|
| 197 |
then `get_deleter()` and `u.get_deleter()` both reference the same
|
|
@@ -216,42 +212,30 @@ unless:
|
|
| 216 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 217 |
|
| 218 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 219 |
to `*this`. If `E` is a reference type, this deleter is copy constructed
|
| 220 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 221 |
-
`u`’s deleter.
|
| 222 |
-
|
|
|
|
|
|
|
| 223 |
|
| 224 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 225 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 226 |
that was constructed from `u.get_deleter()`.
|
| 227 |
|
| 228 |
-
``` cpp
|
| 229 |
-
template <class U>
|
| 230 |
-
unique_ptr(auto_ptr<U>&& u) noexcept;
|
| 231 |
-
```
|
| 232 |
-
|
| 233 |
-
*Effects:* Constructs a `unique_ptr` object, initializing the stored
|
| 234 |
-
pointer with `u.release()` and value-initializing the stored deleter.
|
| 235 |
-
|
| 236 |
-
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 237 |
-
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 238 |
-
to the stored deleter.
|
| 239 |
-
|
| 240 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 241 |
-
unless `U*` is implicitly convertible to `T*` and `D` is the same type
|
| 242 |
-
as `default_delete<T>`.
|
| 243 |
-
|
| 244 |
##### `unique_ptr` destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
|
| 245 |
|
| 246 |
``` cpp
|
| 247 |
~unique_ptr();
|
| 248 |
```
|
| 249 |
|
| 250 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 251 |
-
shall have well-defined behavior, and shall not throw exceptions.
|
| 252 |
-
|
|
|
|
|
|
|
| 253 |
|
| 254 |
*Effects:* If `get() == nullptr` there are no effects. Otherwise
|
| 255 |
`get_deleter()(get())`.
|
| 256 |
|
| 257 |
##### `unique_ptr` assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
|
|
@@ -259,11 +243,11 @@ use of `default_delete` requires `T` to be a complete type.
|
|
| 259 |
``` cpp
|
| 260 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 261 |
```
|
| 262 |
|
| 263 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 264 |
-
requirements of `MoveAssignable` (Table [[moveassignable]]) and
|
| 265 |
assignment of the deleter from an rvalue of type `D` shall not throw an
|
| 266 |
exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
|
| 267 |
shall satisfy the `CopyAssignable` requirements and assignment of the
|
| 268 |
deleter from an lvalue of type `D` shall not throw an exception.
|
| 269 |
|
|
@@ -284,12 +268,14 @@ deleter from an lvalue of type `E` shall be well-formed and shall not
|
|
| 284 |
throw an exception.
|
| 285 |
|
| 286 |
*Remarks:* This operator shall not participate in overload resolution
|
| 287 |
unless:
|
| 288 |
|
| 289 |
-
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`
|
| 290 |
-
|
|
|
|
|
|
|
| 291 |
|
| 292 |
*Effects:* Transfers ownership from `u` to `*this` as if by calling
|
| 293 |
`reset(u.release())` followed by
|
| 294 |
`get_deleter() = std::forward<E>(u.get_deleter())`.
|
| 295 |
|
|
@@ -297,13 +283,13 @@ unless:
|
|
| 297 |
|
| 298 |
``` cpp
|
| 299 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 300 |
```
|
| 301 |
|
| 302 |
-
*Effects:* `reset()`.
|
| 303 |
|
| 304 |
-
`get() == nullptr`
|
| 305 |
|
| 306 |
*Returns:* `*this`.
|
| 307 |
|
| 308 |
##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
|
| 309 |
|
|
@@ -321,11 +307,12 @@ pointer operator->() const noexcept;
|
|
| 321 |
|
| 322 |
*Requires:* `get() != nullptr`.
|
| 323 |
|
| 324 |
*Returns:* `get()`.
|
| 325 |
|
| 326 |
-
*Note
|
|
|
|
| 327 |
|
| 328 |
``` cpp
|
| 329 |
pointer get() const noexcept;
|
| 330 |
```
|
| 331 |
|
|
@@ -348,29 +335,33 @@ explicit operator bool() const noexcept;
|
|
| 348 |
|
| 349 |
``` cpp
|
| 350 |
pointer release() noexcept;
|
| 351 |
```
|
| 352 |
|
| 353 |
-
`get() == nullptr`.
|
| 354 |
|
| 355 |
*Returns:* The value `get()` had at the start of the call to `release`.
|
| 356 |
|
| 357 |
``` cpp
|
| 358 |
void reset(pointer p = pointer()) noexcept;
|
| 359 |
```
|
| 360 |
|
| 361 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 362 |
shall have well-defined behavior, and shall not throw exceptions.
|
| 363 |
|
| 364 |
-
*Effects:*
|
| 365 |
-
of the stored pointer, `old_p`, was not equal to
|
| 366 |
-
`get_deleter()(old_p)`.
|
| 367 |
-
because the call to `get_deleter()` may destroy `*this`.
|
| 368 |
|
| 369 |
-
*
|
| 370 |
-
call to `get_deleter()`
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
``` cpp
|
| 374 |
void swap(unique_ptr& u) noexcept;
|
| 375 |
```
|
| 376 |
|
|
|
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
template <class T, class D = default_delete<T>> class unique_ptr {
|
| 6 |
public:
|
| 7 |
+
using pointer = see below;
|
| 8 |
+
using element_type = T;
|
| 9 |
+
using deleter_type = D;
|
| 10 |
|
| 11 |
// [unique.ptr.single.ctor], constructors
|
| 12 |
constexpr unique_ptr() noexcept;
|
| 13 |
explicit unique_ptr(pointer p) noexcept;
|
| 14 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 15 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 16 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 17 |
+
constexpr unique_ptr(nullptr_t) noexcept;
|
|
|
|
| 18 |
template <class U, class E>
|
| 19 |
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
|
|
|
|
|
|
| 20 |
|
| 21 |
// [unique.ptr.single.dtor], destructor
|
| 22 |
~unique_ptr();
|
| 23 |
|
| 24 |
// [unique.ptr.single.asgn], assignment
|
|
|
|
| 32 |
pointer get() const noexcept;
|
| 33 |
deleter_type& get_deleter() noexcept;
|
| 34 |
const deleter_type& get_deleter() const noexcept;
|
| 35 |
explicit operator bool() const noexcept;
|
| 36 |
|
| 37 |
+
// [unique.ptr.single.modifiers], modifiers
|
| 38 |
pointer release() noexcept;
|
| 39 |
void reset(pointer p = pointer()) noexcept;
|
| 40 |
void swap(unique_ptr& u) noexcept;
|
| 41 |
|
| 42 |
// disable copy from lvalue
|
|
|
|
| 46 |
}
|
| 47 |
```
|
| 48 |
|
| 49 |
The default type for the template parameter `D` is `default_delete`. A
|
| 50 |
client-supplied template argument `D` shall be a function object type (
|
| 51 |
+
[[function.objects]]), lvalue reference to function, or lvalue reference
|
| 52 |
to function object type for which, given a value `d` of type `D` and a
|
| 53 |
value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
|
| 54 |
is valid and has the effect of disposing of the pointer as appropriate
|
| 55 |
for that deleter.
|
| 56 |
|
| 57 |
If the deleter’s type `D` is not a reference type, `D` shall satisfy the
|
| 58 |
+
requirements of `Destructible` (Table [[tab:destructible]]).
|
| 59 |
|
| 60 |
+
If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
|
| 61 |
+
denotes a type ([[temp.deduct]]), then `unique_ptr<T,
|
| 62 |
D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
|
| 63 |
+
Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
|
| 64 |
+
`element_type*`. The type `unique_ptr<T,
|
| 65 |
D>::pointer` shall satisfy the requirements of `NullablePointer` (
|
| 66 |
[[nullablepointer.requirements]]).
|
| 67 |
|
| 68 |
+
[*Example 1*: Given an allocator type `X` ([[allocator.requirements]])
|
| 69 |
+
and letting `A` be a synonym for `allocator_traits<X>`, the types
|
| 70 |
+
`A::pointer`, `A::const_pointer`, `A::void_pointer`, and
|
| 71 |
+
`A::const_void_pointer` may be used as
|
| 72 |
+
`unique_ptr<T, D>::pointer`. — *end example*]
|
| 73 |
|
| 74 |
##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 75 |
|
| 76 |
``` cpp
|
| 77 |
constexpr unique_ptr() noexcept;
|
| 78 |
+
constexpr unique_ptr(nullptr_t) noexcept;
|
| 79 |
```
|
| 80 |
|
| 81 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 82 |
+
(Table [[tab:defaultconstructible]]), and that construction shall not
|
| 83 |
+
throw an exception.
|
| 84 |
|
| 85 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 86 |
value-initializing the stored pointer and the stored deleter.
|
| 87 |
|
| 88 |
*Postconditions:* `get() == nullptr`. `get_deleter()` returns a
|
| 89 |
reference to the stored deleter.
|
| 90 |
|
| 91 |
+
*Remarks:* If `is_pointer_v<deleter_type>` is `true` or
|
| 92 |
+
`is_default_constructible_v<deleter_type>` is `false`, this constructor
|
| 93 |
+
shall not participate in overload resolution.
|
| 94 |
|
| 95 |
``` cpp
|
| 96 |
explicit unique_ptr(pointer p) noexcept;
|
| 97 |
```
|
| 98 |
|
| 99 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 100 |
+
(Table [[tab:defaultconstructible]]), and that construction shall not
|
| 101 |
+
throw an exception.
|
| 102 |
|
| 103 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 104 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 105 |
|
| 106 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 107 |
the stored deleter.
|
| 108 |
|
| 109 |
+
*Remarks:* If `is_pointer_v<deleter_type>` is `true` or
|
| 110 |
+
`is_default_constructible_v<deleter_type>` is `false`, this constructor
|
| 111 |
+
shall not participate in overload resolution. If class template argument
|
| 112 |
+
deduction ([[over.match.class.deduct]]) would select the function
|
| 113 |
+
template corresponding to this constructor, then the program is
|
| 114 |
+
ill-formed.
|
| 115 |
|
| 116 |
``` cpp
|
| 117 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 118 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 119 |
```
|
| 120 |
|
| 121 |
The signature of these constructors depends upon whether `D` is a
|
| 122 |
+
reference type. If `D` is a non-reference type `A`, then the signatures
|
| 123 |
are:
|
| 124 |
|
| 125 |
``` cpp
|
| 126 |
+
unique_ptr(pointer p, const A& d) noexcept;
|
| 127 |
+
unique_ptr(pointer p, A&& d) noexcept;
|
| 128 |
```
|
| 129 |
|
| 130 |
+
If `D` is an lvalue reference type `A&`, then the signatures are:
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
+
unique_ptr(pointer p, A& d) noexcept;
|
| 134 |
+
unique_ptr(pointer p, A&& d) = delete;
|
| 135 |
```
|
| 136 |
|
| 137 |
+
If `D` is an lvalue reference type `const A&`, then the signatures are:
|
| 138 |
|
| 139 |
``` cpp
|
| 140 |
+
unique_ptr(pointer p, const A& d) noexcept;
|
| 141 |
+
unique_ptr(pointer p, const A&& d) = delete;
|
| 142 |
```
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 145 |
+
the stored pointer with `p` and initializing the deleter from
|
| 146 |
+
`std::forward<decltype(d)>(d)`.
|
| 147 |
+
|
| 148 |
+
*Remarks:* These constructors shall not participate in overload
|
| 149 |
+
resolution unless `is_constructible_v<D, decltype(d)>` is `true`.
|
| 150 |
|
| 151 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 152 |
the stored deleter. If `D` is a reference type then `get_deleter()`
|
| 153 |
returns a reference to the lvalue `d`.
|
| 154 |
|
| 155 |
+
*Remarks:* If class template argument
|
| 156 |
+
deduction ([[over.match.class.deduct]]) would select a function
|
| 157 |
+
template corresponding to either of these constructors, then the program
|
| 158 |
+
is ill-formed.
|
| 159 |
+
|
| 160 |
+
[*Example 1*:
|
| 161 |
+
|
| 162 |
``` cpp
|
| 163 |
D d;
|
| 164 |
unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
|
| 165 |
unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
|
| 166 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 167 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 168 |
// with reference deleter type
|
| 169 |
```
|
| 170 |
|
| 171 |
+
— *end example*]
|
| 172 |
+
|
| 173 |
``` cpp
|
| 174 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 175 |
```
|
| 176 |
|
| 177 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 178 |
+
requirements of `MoveConstructible` (Table [[tab:moveconstructible]]).
|
| 179 |
Construction of the deleter from an rvalue of type `D` shall not throw
|
| 180 |
an exception.
|
| 181 |
|
| 182 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 183 |
to `*this`. If `D` is a reference type, this deleter is copy constructed
|
| 184 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 185 |
+
`u`’s deleter.
|
| 186 |
+
|
| 187 |
+
[*Note 1*: The deleter constructor can be implemented with
|
| 188 |
+
`std::forward<D>`. — *end note*]
|
| 189 |
|
| 190 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 191 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 192 |
that was constructed from `u.get_deleter()`. If `D` is a reference type
|
| 193 |
then `get_deleter()` and `u.get_deleter()` both reference the same
|
|
|
|
| 212 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 213 |
|
| 214 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 215 |
to `*this`. If `E` is a reference type, this deleter is copy constructed
|
| 216 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 217 |
+
`u`’s deleter.
|
| 218 |
+
|
| 219 |
+
[*Note 2*: The deleter constructor can be implemented with
|
| 220 |
+
`std::forward<E>`. — *end note*]
|
| 221 |
|
| 222 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 223 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 224 |
that was constructed from `u.get_deleter()`.
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
##### `unique_ptr` destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
|
| 227 |
|
| 228 |
``` cpp
|
| 229 |
~unique_ptr();
|
| 230 |
```
|
| 231 |
|
| 232 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 233 |
+
shall have well-defined behavior, and shall not throw exceptions.
|
| 234 |
+
|
| 235 |
+
[*Note 3*: The use of `default_delete` requires `T` to be a complete
|
| 236 |
+
type. — *end note*]
|
| 237 |
|
| 238 |
*Effects:* If `get() == nullptr` there are no effects. Otherwise
|
| 239 |
`get_deleter()(get())`.
|
| 240 |
|
| 241 |
##### `unique_ptr` assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
|
|
|
|
| 243 |
``` cpp
|
| 244 |
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
| 245 |
```
|
| 246 |
|
| 247 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 248 |
+
requirements of `MoveAssignable` (Table [[tab:moveassignable]]) and
|
| 249 |
assignment of the deleter from an rvalue of type `D` shall not throw an
|
| 250 |
exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
|
| 251 |
shall satisfy the `CopyAssignable` requirements and assignment of the
|
| 252 |
deleter from an lvalue of type `D` shall not throw an exception.
|
| 253 |
|
|
|
|
| 268 |
throw an exception.
|
| 269 |
|
| 270 |
*Remarks:* This operator shall not participate in overload resolution
|
| 271 |
unless:
|
| 272 |
|
| 273 |
+
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 274 |
+
and
|
| 275 |
+
- `U` is not an array type, and
|
| 276 |
+
- `is_assignable_v<D&, E&&>` is `true`.
|
| 277 |
|
| 278 |
*Effects:* Transfers ownership from `u` to `*this` as if by calling
|
| 279 |
`reset(u.release())` followed by
|
| 280 |
`get_deleter() = std::forward<E>(u.get_deleter())`.
|
| 281 |
|
|
|
|
| 283 |
|
| 284 |
``` cpp
|
| 285 |
unique_ptr& operator=(nullptr_t) noexcept;
|
| 286 |
```
|
| 287 |
|
| 288 |
+
*Effects:* As if by `reset()`.
|
| 289 |
|
| 290 |
+
*Postconditions:* `get() == nullptr`.
|
| 291 |
|
| 292 |
*Returns:* `*this`.
|
| 293 |
|
| 294 |
##### `unique_ptr` observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
|
| 295 |
|
|
|
|
| 307 |
|
| 308 |
*Requires:* `get() != nullptr`.
|
| 309 |
|
| 310 |
*Returns:* `get()`.
|
| 311 |
|
| 312 |
+
[*Note 4*: The use of this function typically requires that `T` be a
|
| 313 |
+
complete type. — *end note*]
|
| 314 |
|
| 315 |
``` cpp
|
| 316 |
pointer get() const noexcept;
|
| 317 |
```
|
| 318 |
|
|
|
|
| 335 |
|
| 336 |
``` cpp
|
| 337 |
pointer release() noexcept;
|
| 338 |
```
|
| 339 |
|
| 340 |
+
*Postconditions:* `get() == nullptr`.
|
| 341 |
|
| 342 |
*Returns:* The value `get()` had at the start of the call to `release`.
|
| 343 |
|
| 344 |
``` cpp
|
| 345 |
void reset(pointer p = pointer()) noexcept;
|
| 346 |
```
|
| 347 |
|
| 348 |
*Requires:* The expression `get_deleter()(get())` shall be well formed,
|
| 349 |
shall have well-defined behavior, and shall not throw exceptions.
|
| 350 |
|
| 351 |
+
*Effects:* Assigns `p` to the stored pointer, and then if and only if
|
| 352 |
+
the old value of the stored pointer, `old_p`, was not equal to
|
| 353 |
+
`nullptr`, calls `get_deleter()(old_p)`.
|
|
|
|
| 354 |
|
| 355 |
+
[*Note 5*: The order of these operations is significant because the
|
| 356 |
+
call to `get_deleter()` may destroy `*this`. — *end note*]
|
| 357 |
+
|
| 358 |
+
*Postconditions:* `get() == p`.
|
| 359 |
+
|
| 360 |
+
[*Note 6*: The postcondition does not hold if the call to
|
| 361 |
+
`get_deleter()` destroys `*this` since `this->get()` is no longer a
|
| 362 |
+
valid expression. — *end note*]
|
| 363 |
|
| 364 |
``` cpp
|
| 365 |
void swap(unique_ptr& u) noexcept;
|
| 366 |
```
|
| 367 |
|