From Jason Turner

[unique.ptr.single]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzht9g5wq/{from.md → to.md} +60 -64
tmp/tmpzht9g5wq/{from.md → to.md} RENAMED
@@ -1,46 +1,48 @@
1
  #### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
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
25
- unique_ptr& operator=(unique_ptr&& u) noexcept;
26
  template<class U, class E>
27
- unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
28
- unique_ptr& operator=(nullptr_t) noexcept;
29
 
30
  // [unique.ptr.single.observers], observers
31
- add_lvalue_reference_t<T> operator*() const;
32
- pointer operator->() const noexcept;
33
- pointer get() const noexcept;
34
- deleter_type& get_deleter() noexcept;
35
- const deleter_type& get_deleter() const noexcept;
36
- explicit operator bool() const noexcept;
37
 
38
  // [unique.ptr.single.modifiers], modifiers
39
- pointer release() noexcept;
40
- void reset(pointer p = pointer()) noexcept;
41
- void swap(unique_ptr& u) noexcept;
42
 
43
  // disable copy from lvalue
44
  unique_ptr(const unique_ptr&) = delete;
45
  unique_ptr& operator=(const unique_ptr&) = delete;
46
  };
@@ -64,46 +66,43 @@ D>::pointer` shall be a synonym for `remove_reference_t<D>::pointer`.
64
  Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
65
  `element_type*`. The type `unique_ptr<T,
66
  D>::pointer` shall meet the *Cpp17NullablePointer* requirements (
67
  [[cpp17.nullablepointer]]).
68
 
69
- [*Example 1*: Given an allocator type `X` ([[cpp17.allocator]]) and
70
- letting `A` be a synonym for `allocator_traits<X>`, the types
71
- `A::pointer`, `A::const_pointer`, `A::void_pointer`, and
72
- `A::const_void_pointer` may be used as
73
  `unique_ptr<T, D>::pointer`. — *end example*]
74
 
75
  ##### Constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
76
 
77
  ``` cpp
78
  constexpr unique_ptr() noexcept;
79
  constexpr unique_ptr(nullptr_t) noexcept;
80
  ```
81
 
 
 
 
82
  *Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
83
  ([[cpp17.defaultconstructible]]), and that construction does not throw
84
  an exception.
85
 
86
- *Constraints:* `is_pointer_v<deleter_type>` is `false` and
87
- `is_default_constructible_v<deleter_type>` is `true`.
88
-
89
  *Effects:* Constructs a `unique_ptr` object that owns nothing,
90
  value-initializing the stored pointer and the stored deleter.
91
 
92
  *Ensures:* `get() == nullptr`. `get_deleter()` returns a reference to
93
  the stored deleter.
94
 
95
  ``` cpp
96
- explicit unique_ptr(pointer p) noexcept;
97
  ```
98
 
99
  *Constraints:* `is_pointer_v<deleter_type>` is `false` and
100
  `is_default_constructible_v<deleter_type>` is `true`.
101
 
102
- *Mandates:* This constructor is not selected by class template argument
103
- deduction [[over.match.class.deduct]].
104
-
105
  *Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
106
  ([[cpp17.defaultconstructible]]), and that construction does not throw
107
  an exception.
108
 
109
  *Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
@@ -111,19 +110,16 @@ stored pointer with `p` and value-initializing the stored deleter.
111
 
112
  *Ensures:* `get() == p`. `get_deleter()` returns a reference to the
113
  stored deleter.
114
 
115
  ``` cpp
116
- unique_ptr(pointer p, const D& d) noexcept;
117
- unique_ptr(pointer p, remove_reference_t<D>&& d) noexcept;
118
  ```
119
 
120
  *Constraints:* `is_constructible_v<D, decltype(d)>` is `true`.
121
 
122
- *Mandates:* These constructors are not selected by class template
123
- argument deduction [[over.match.class.deduct]].
124
-
125
  *Preconditions:* For the first constructor, if `D` is not a reference
126
  type, `D` meets the *Cpp17CopyConstructible* requirements and such
127
  construction does not exit via an exception. For the second constructor,
128
  if `D` is not a reference type, `D` meets the *Cpp17MoveConstructible*
129
  requirements and such construction does not exit via an exception.
@@ -151,11 +147,11 @@ unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object comb
151
  ```
152
 
153
  — *end example*]
154
 
155
  ``` cpp
156
- unique_ptr(unique_ptr&& u) noexcept;
157
  ```
158
 
159
  *Constraints:* `is_move_constructible_v<D>` is `true`.
160
 
161
  *Preconditions:* If `D` is not a reference type, `D` meets the
@@ -175,11 +171,11 @@ construction. `u.get() == nullptr`. `get_deleter()` returns a reference
175
  to the stored deleter that was constructed from `u.get_deleter()`. If
176
  `D` is a reference type then `get_deleter()` and `u.get_deleter()` both
177
  reference the same lvalue deleter.
178
 
179
  ``` cpp
180
- template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
181
  ```
182
 
183
  *Constraints:*
184
 
185
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
@@ -205,26 +201,25 @@ construction. `u.get() == nullptr`. `get_deleter()` returns a reference
205
  to the stored deleter that was constructed from `u.get_deleter()`.
206
 
207
  ##### Destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
208
 
209
  ``` cpp
210
- ~unique_ptr();
211
  ```
212
 
213
- *Preconditions:* The expression `get_deleter()(get())` is well-formed,
214
- has well-defined behavior, and does not throw exceptions.
215
 
216
  [*Note 3*: The use of `default_delete` requires `T` to be a complete
217
  type. — *end note*]
218
 
219
- *Effects:* If `get() == nullptr` there are no effects. Otherwise
220
- `get_deleter()(get())`.
221
 
222
  ##### Assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
223
 
224
  ``` cpp
225
- unique_ptr& operator=(unique_ptr&& u) noexcept;
226
  ```
227
 
228
  *Constraints:* `is_move_assignable_v<D>` is `true`.
229
 
230
  *Preconditions:* If `D` is not a reference type, `D` meets the
@@ -235,16 +230,17 @@ meets the *Cpp17CopyAssignable* requirements and assignment of the
235
  deleter from an lvalue of type `D` does not throw an exception.
236
 
237
  *Effects:* Calls `reset(u.release())` followed by
238
  `get_deleter() = std::forward<D>(u.get_deleter())`.
239
 
 
 
 
240
  *Returns:* `*this`.
241
 
242
- *Ensures:* `u.get() == nullptr`.
243
-
244
  ``` cpp
245
- template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
246
  ```
247
 
248
  *Constraints:*
249
 
250
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
@@ -259,16 +255,16 @@ deleter from an lvalue of type `E` is well-formed and does not throw an
259
  exception.
260
 
261
  *Effects:* Calls `reset(u.release())` followed by
262
  `get_deleter() = std::forward<E>(u.get_deleter())`.
263
 
264
- *Returns:* `*this`.
265
-
266
  *Ensures:* `u.get() == nullptr`.
267
 
 
 
268
  ``` cpp
269
- unique_ptr& operator=(nullptr_t) noexcept;
270
  ```
271
 
272
  *Effects:* As if by `reset()`.
273
 
274
  *Ensures:* `get() == nullptr`.
@@ -276,79 +272,79 @@ unique_ptr& operator=(nullptr_t) noexcept;
276
  *Returns:* `*this`.
277
 
278
  ##### Observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
279
 
280
  ``` cpp
281
- add_lvalue_reference_t<T> operator*() const;
282
  ```
283
 
284
  *Preconditions:* `get() != nullptr`.
285
 
286
  *Returns:* `*get()`.
287
 
288
  ``` cpp
289
- pointer operator->() const noexcept;
290
  ```
291
 
292
  *Preconditions:* `get() != nullptr`.
293
 
294
  *Returns:* `get()`.
295
 
296
  [*Note 4*: The use of this function typically requires that `T` be a
297
  complete type. — *end note*]
298
 
299
  ``` cpp
300
- pointer get() const noexcept;
301
  ```
302
 
303
  *Returns:* The stored pointer.
304
 
305
  ``` cpp
306
- deleter_type& get_deleter() noexcept;
307
- const deleter_type& get_deleter() const noexcept;
308
  ```
309
 
310
  *Returns:* A reference to the stored deleter.
311
 
312
  ``` cpp
313
- explicit operator bool() const noexcept;
314
  ```
315
 
316
  *Returns:* `get() != nullptr`.
317
 
318
  ##### Modifiers <a id="unique.ptr.single.modifiers">[[unique.ptr.single.modifiers]]</a>
319
 
320
  ``` cpp
321
- pointer release() noexcept;
322
  ```
323
 
324
  *Ensures:* `get() == nullptr`.
325
 
326
  *Returns:* The value `get()` had at the start of the call to `release`.
327
 
328
  ``` cpp
329
- void reset(pointer p = pointer()) noexcept;
330
  ```
331
 
332
- *Preconditions:* The expression `get_deleter()(get())` is well-formed,
333
- has well-defined behavior, and does not throw exceptions.
334
-
335
- *Effects:* Assigns `p` to the stored pointer, and then if and only if
336
- the old value of the stored pointer, `old_p`, was not equal to
337
- `nullptr`, calls `get_deleter()(old_p)`.
338
 
339
  [*Note 5*: The order of these operations is significant because the
340
- call to `get_deleter()` may destroy `*this`. — *end note*]
341
 
342
  *Ensures:* `get() == p`.
343
 
344
  [*Note 6*: The postcondition does not hold if the call to
345
  `get_deleter()` destroys `*this` since `this->get()` is no longer a
346
  valid expression. — *end note*]
347
 
 
 
 
348
  ``` cpp
349
- void swap(unique_ptr& u) noexcept;
350
  ```
351
 
352
  *Preconditions:* `get_deleter()` is swappable [[swappable.requirements]]
353
  and does not throw an exception under `swap`.
354
 
 
1
  #### `unique_ptr` for single objects <a id="unique.ptr.single">[[unique.ptr.single]]</a>
2
 
3
+ ##### General <a id="unique.ptr.single.general">[[unique.ptr.single.general]]</a>
4
+
5
  ``` cpp
6
  namespace std {
7
  template<class T, class D = default_delete<T>> class unique_ptr {
8
  public:
9
  using pointer = see below;
10
  using element_type = T;
11
  using deleter_type = D;
12
 
13
  // [unique.ptr.single.ctor], constructors
14
  constexpr unique_ptr() noexcept;
15
+ constexpr explicit unique_ptr(type_identity_t<pointer> p) noexcept;
16
+ constexpr unique_ptr(type_identity_t<pointer> p, see below d1) noexcept;
17
+ constexpr unique_ptr(type_identity_t<pointer> p, see below d2) noexcept;
18
+ constexpr unique_ptr(unique_ptr&& u) noexcept;
19
  constexpr unique_ptr(nullptr_t) noexcept;
20
  template<class U, class E>
21
+ constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept;
22
 
23
  // [unique.ptr.single.dtor], destructor
24
+ constexpr ~unique_ptr();
25
 
26
  // [unique.ptr.single.asgn], assignment
27
+ constexpr unique_ptr& operator=(unique_ptr&& u) noexcept;
28
  template<class U, class E>
29
+ constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
30
+ constexpr unique_ptr& operator=(nullptr_t) noexcept;
31
 
32
  // [unique.ptr.single.observers], observers
33
+ constexpr add_lvalue_reference_t<T> operator*() const noexcept(see below);
34
+ constexpr pointer operator->() const noexcept;
35
+ constexpr pointer get() const noexcept;
36
+ constexpr deleter_type& get_deleter() noexcept;
37
+ constexpr const deleter_type& get_deleter() const noexcept;
38
+ constexpr explicit operator bool() const noexcept;
39
 
40
  // [unique.ptr.single.modifiers], modifiers
41
+ constexpr pointer release() noexcept;
42
+ constexpr void reset(pointer p = pointer()) noexcept;
43
+ constexpr void swap(unique_ptr& u) noexcept;
44
 
45
  // disable copy from lvalue
46
  unique_ptr(const unique_ptr&) = delete;
47
  unique_ptr& operator=(const unique_ptr&) = delete;
48
  };
 
66
  Otherwise `unique_ptr<T, D>::pointer` shall be a synonym for
67
  `element_type*`. The type `unique_ptr<T,
68
  D>::pointer` shall meet the *Cpp17NullablePointer* requirements (
69
  [[cpp17.nullablepointer]]).
70
 
71
+ [*Example 1*: Given an allocator type `X`
72
+ [[allocator.requirements.general]] and letting `A` be a synonym for
73
+ `allocator_traits<X>`, the types `A::pointer`, `A::const_pointer`,
74
+ `A::void_pointer`, and `A::const_void_pointer` may be used as
75
  `unique_ptr<T, D>::pointer`. — *end example*]
76
 
77
  ##### Constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
78
 
79
  ``` cpp
80
  constexpr unique_ptr() noexcept;
81
  constexpr unique_ptr(nullptr_t) noexcept;
82
  ```
83
 
84
+ *Constraints:* `is_pointer_v<deleter_type>` is `false` and
85
+ `is_default_constructible_v<deleter_type>` is `true`.
86
+
87
  *Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
88
  ([[cpp17.defaultconstructible]]), and that construction does not throw
89
  an exception.
90
 
 
 
 
91
  *Effects:* Constructs a `unique_ptr` object that owns nothing,
92
  value-initializing the stored pointer and the stored deleter.
93
 
94
  *Ensures:* `get() == nullptr`. `get_deleter()` returns a reference to
95
  the stored deleter.
96
 
97
  ``` cpp
98
+ constexpr explicit unique_ptr(type_identity_t<pointer> p) noexcept;
99
  ```
100
 
101
  *Constraints:* `is_pointer_v<deleter_type>` is `false` and
102
  `is_default_constructible_v<deleter_type>` is `true`.
103
 
 
 
 
104
  *Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
105
  ([[cpp17.defaultconstructible]]), and that construction does not throw
106
  an exception.
107
 
108
  *Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
 
110
 
111
  *Ensures:* `get() == p`. `get_deleter()` returns a reference to the
112
  stored deleter.
113
 
114
  ``` cpp
115
+ constexpr unique_ptr(type_identity_t<pointer> p, const D& d) noexcept;
116
+ constexpr unique_ptr(type_identity_t<pointer> p, remove_reference_t<D>&& d) noexcept;
117
  ```
118
 
119
  *Constraints:* `is_constructible_v<D, decltype(d)>` is `true`.
120
 
 
 
 
121
  *Preconditions:* For the first constructor, if `D` is not a reference
122
  type, `D` meets the *Cpp17CopyConstructible* requirements and such
123
  construction does not exit via an exception. For the second constructor,
124
  if `D` is not a reference type, `D` meets the *Cpp17MoveConstructible*
125
  requirements and such construction does not exit via an exception.
 
147
  ```
148
 
149
  — *end example*]
150
 
151
  ``` cpp
152
+ constexpr unique_ptr(unique_ptr&& u) noexcept;
153
  ```
154
 
155
  *Constraints:* `is_move_constructible_v<D>` is `true`.
156
 
157
  *Preconditions:* If `D` is not a reference type, `D` meets the
 
171
  to the stored deleter that was constructed from `u.get_deleter()`. If
172
  `D` is a reference type then `get_deleter()` and `u.get_deleter()` both
173
  reference the same lvalue deleter.
174
 
175
  ``` cpp
176
+ template<class U, class E> constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept;
177
  ```
178
 
179
  *Constraints:*
180
 
181
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
 
201
  to the stored deleter that was constructed from `u.get_deleter()`.
202
 
203
  ##### Destructor <a id="unique.ptr.single.dtor">[[unique.ptr.single.dtor]]</a>
204
 
205
  ``` cpp
206
+ constexpr ~unique_ptr();
207
  ```
208
 
209
+ *Effects:* Equivalent to: `if (get()) get_deleter()(get());`
 
210
 
211
  [*Note 3*: The use of `default_delete` requires `T` to be a complete
212
  type. — *end note*]
213
 
214
+ *Remarks:* The behavior is undefined if the evaluation of
215
+ `get_deleter()(get())` throws an exception.
216
 
217
  ##### Assignment <a id="unique.ptr.single.asgn">[[unique.ptr.single.asgn]]</a>
218
 
219
  ``` cpp
220
+ constexpr unique_ptr& operator=(unique_ptr&& u) noexcept;
221
  ```
222
 
223
  *Constraints:* `is_move_assignable_v<D>` is `true`.
224
 
225
  *Preconditions:* If `D` is not a reference type, `D` meets the
 
230
  deleter from an lvalue of type `D` does not throw an exception.
231
 
232
  *Effects:* Calls `reset(u.release())` followed by
233
  `get_deleter() = std::forward<D>(u.get_deleter())`.
234
 
235
+ *Ensures:* If `this != addressof(u)`, `u.get() == nullptr`, otherwise
236
+ `u.get()` is unchanged.
237
+
238
  *Returns:* `*this`.
239
 
 
 
240
  ``` cpp
241
+ template<class U, class E> constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
242
  ```
243
 
244
  *Constraints:*
245
 
246
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
 
255
  exception.
256
 
257
  *Effects:* Calls `reset(u.release())` followed by
258
  `get_deleter() = std::forward<E>(u.get_deleter())`.
259
 
 
 
260
  *Ensures:* `u.get() == nullptr`.
261
 
262
+ *Returns:* `*this`.
263
+
264
  ``` cpp
265
+ constexpr unique_ptr& operator=(nullptr_t) noexcept;
266
  ```
267
 
268
  *Effects:* As if by `reset()`.
269
 
270
  *Ensures:* `get() == nullptr`.
 
272
  *Returns:* `*this`.
273
 
274
  ##### Observers <a id="unique.ptr.single.observers">[[unique.ptr.single.observers]]</a>
275
 
276
  ``` cpp
277
+ constexpr add_lvalue_reference_t<T> operator*() const noexcept(noexcept(*declval<pointer>()));
278
  ```
279
 
280
  *Preconditions:* `get() != nullptr`.
281
 
282
  *Returns:* `*get()`.
283
 
284
  ``` cpp
285
+ constexpr pointer operator->() const noexcept;
286
  ```
287
 
288
  *Preconditions:* `get() != nullptr`.
289
 
290
  *Returns:* `get()`.
291
 
292
  [*Note 4*: The use of this function typically requires that `T` be a
293
  complete type. — *end note*]
294
 
295
  ``` cpp
296
+ constexpr pointer get() const noexcept;
297
  ```
298
 
299
  *Returns:* The stored pointer.
300
 
301
  ``` cpp
302
+ constexpr deleter_type& get_deleter() noexcept;
303
+ constexpr const deleter_type& get_deleter() const noexcept;
304
  ```
305
 
306
  *Returns:* A reference to the stored deleter.
307
 
308
  ``` cpp
309
+ constexpr explicit operator bool() const noexcept;
310
  ```
311
 
312
  *Returns:* `get() != nullptr`.
313
 
314
  ##### Modifiers <a id="unique.ptr.single.modifiers">[[unique.ptr.single.modifiers]]</a>
315
 
316
  ``` cpp
317
+ constexpr pointer release() noexcept;
318
  ```
319
 
320
  *Ensures:* `get() == nullptr`.
321
 
322
  *Returns:* The value `get()` had at the start of the call to `release`.
323
 
324
  ``` cpp
325
+ constexpr void reset(pointer p = pointer()) noexcept;
326
  ```
327
 
328
+ *Effects:* Assigns `p` to the stored pointer, and then, with the old
329
+ value of the stored pointer, `old_p`, evaluates
330
+ `if (old_p) get_deleter()(old_p);`
 
 
 
331
 
332
  [*Note 5*: The order of these operations is significant because the
333
+ call to `get_deleter()` might destroy `*this`. — *end note*]
334
 
335
  *Ensures:* `get() == p`.
336
 
337
  [*Note 6*: The postcondition does not hold if the call to
338
  `get_deleter()` destroys `*this` since `this->get()` is no longer a
339
  valid expression. — *end note*]
340
 
341
+ *Remarks:* The behavior is undefined if the evaluation of
342
+ `get_deleter()(old_p)` throws an exception.
343
+
344
  ``` cpp
345
+ constexpr void swap(unique_ptr& u) noexcept;
346
  ```
347
 
348
  *Preconditions:* `get_deleter()` is swappable [[swappable.requirements]]
349
  and does not throw an exception under `swap`.
350