From Jason Turner

[unique.ptr.single]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1zha6m98/{from.md → to.md} +111 -128
tmp/tmp1zha6m98/{from.md → to.md} RENAMED
@@ -21,11 +21,12 @@ namespace std {
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> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
 
27
  unique_ptr& operator=(nullptr_t) noexcept;
28
 
29
  // [unique.ptr.single.observers], observers
30
  add_lvalue_reference_t<T> operator*() const;
31
  pointer operator->() const noexcept;
@@ -45,126 +46,107 @@ namespace std {
45
  };
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
 
@@ -172,142 +154,144 @@ unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object comb
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
194
- lvalue deleter.
195
 
196
  ``` cpp
197
  template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
198
  ```
199
 
200
- *Requires:* If `E` is not a reference type, construction of the deleter
201
- from an rvalue of type `E` shall be well formed and shall not throw an
202
- exception. Otherwise, `E` is a reference type and construction of the
203
- deleter from an lvalue of type `E` shall be well formed and shall not
204
- throw an exception.
205
-
206
- *Remarks:* This constructor shall not participate in overload resolution
207
- unless:
208
 
209
  - `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
210
  - `U` is not an array type, and
211
  - either `D` is a reference type and `E` is the same type as `D`, or `D`
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>
242
 
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
 
254
- *Effects:* Transfers ownership from `u` to `*this` as if by calling
255
- `reset(u.release())` followed by
256
  `get_deleter() = std::forward<D>(u.get_deleter())`.
257
 
258
  *Returns:* `*this`.
259
 
 
 
260
  ``` cpp
261
  template<class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
262
  ```
263
 
264
- *Requires:* If `E` is not a reference type, assignment of the deleter
265
- from an rvalue of type `E` shall be well-formed and shall not throw an
266
- exception. Otherwise, `E` is a reference type and assignment of the
267
- deleter from an lvalue of type `E` shall be well-formed and shall not
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
 
282
  *Returns:* `*this`.
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
 
296
  ``` cpp
297
  add_lvalue_reference_t<T> operator*() const;
298
  ```
299
 
300
- *Requires:* `get() != nullptr`.
301
 
302
  *Returns:* `*get()`.
303
 
304
  ``` cpp
305
  pointer operator->() const noexcept;
306
  ```
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*]
@@ -329,46 +313,45 @@ const deleter_type& get_deleter() const noexcept;
329
  explicit operator bool() const noexcept;
330
  ```
331
 
332
  *Returns:* `get() != nullptr`.
333
 
334
- ##### `unique_ptr` modifiers <a id="unique.ptr.single.modifiers">[[unique.ptr.single.modifiers]]</a>
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
 
368
- *Requires:* `get_deleter()` shall be
369
- swappable ([[swappable.requirements]]) and shall not throw an exception
370
- under `swap`.
371
 
372
  *Effects:* Invokes `swap` on the stored pointers and on the stored
373
  deleters of `*this` and `u`.
374
 
 
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;
 
46
  };
47
  }
48
  ```
49
 
50
  The default type for the template parameter `D` is `default_delete`. A
51
+ client-supplied template argument `D` shall be a function object type
52
+ [[function.objects]], lvalue reference to function, or lvalue reference
53
  to function object type for which, given a value `d` of type `D` and a
54
  value `ptr` of type `unique_ptr<T, D>::pointer`, the expression `d(ptr)`
55
  is valid and has the effect of disposing of the pointer as appropriate
56
  for that deleter.
57
 
58
+ If the deleter’s type `D` is not a reference type, `D` shall meet the
59
+ *Cpp17Destructible* requirements ([[cpp17.destructible]]).
60
 
61
  If the *qualified-id* `remove_reference_t<D>::pointer` is valid and
62
+ denotes a type [[temp.deduct]], then `unique_ptr<T,
63
  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
110
  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.
130
 
131
  *Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
132
  the stored pointer with `p` and initializing the deleter from
133
  `std::forward<decltype(d)>(d)`.
134
 
135
+ *Ensures:* `get() == p`. `get_deleter()` returns a reference to the
136
+ stored deleter. If `D` is a reference type then `get_deleter()` returns
137
+ a reference to the lvalue `d`.
138
 
139
+ *Remarks:* If `D` is a reference type, the second constructor is defined
140
+ as deleted.
 
 
 
 
 
 
141
 
142
  [*Example 1*:
143
 
144
  ``` cpp
145
  D d;
146
+ unique_ptr<int, D> p1(new int, D()); // D must be Cpp17MoveConstructible
147
+ unique_ptr<int, D> p2(new int, d); // D must be Cpp17CopyConstructible
148
  unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
149
  unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
150
  // with reference deleter type
151
  ```
152
 
 
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
162
+ *Cpp17MoveConstructible* requirements ([[cpp17.moveconstructible]]).
163
+ Construction of the deleter from an rvalue of type `D` does not throw an
164
+ exception.
165
 
166
+ *Effects:* Constructs a `unique_ptr` from `u`. If `D` is a reference
167
+ type, this deleter is copy constructed from `u`’s deleter; otherwise,
168
+ this deleter is move constructed from `u`’s deleter.
169
+
170
+ [*Note 1*: The construction of the deleter can be implemented with
171
  `std::forward<D>`. — *end note*]
172
 
173
+ *Ensures:* `get()` yields the value `u.get()` yielded before the
174
+ 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`,
186
  - `U` is not an array type, and
187
  - either `D` is a reference type and `E` is the same type as `D`, or `D`
188
  is not a reference type and `E` is implicitly convertible to `D`.
189
 
190
+ *Preconditions:* If `E` is not a reference type, construction of the
191
+ deleter from an rvalue of type `E` is well-formed and does not throw an
192
+ exception. Otherwise, `E` is a reference type and construction of the
193
+ deleter from an lvalue of type `E` is well-formed and does not throw an
194
+ exception.
195
+
196
+ *Effects:* Constructs a `unique_ptr` from `u`. If `E` is a reference
197
+ type, this deleter is copy constructed from `u`’s deleter; otherwise,
198
+ this deleter is move constructed from `u`’s deleter.
199
 
200
  [*Note 2*: The deleter constructor can be implemented with
201
  `std::forward<E>`. — *end note*]
202
 
203
+ *Ensures:* `get()` yields the value `u.get()` yielded before the
204
+ 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
231
+ *Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]) and
232
+ assignment of the deleter from an rvalue of type `D` does not throw an
233
  exception. Otherwise, `D` is a reference type; `remove_reference_t<D>`
234
+ 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`,
251
  and
252
  - `U` is not an array type, and
253
  - `is_assignable_v<D&, E&&>` is `true`.
254
 
255
+ *Preconditions:* If `E` is not a reference type, assignment of the
256
+ deleter from an rvalue of type `E` is well-formed and does not throw an
257
+ exception. Otherwise, `E` is a reference type and assignment of the
258
+ 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`.
275
 
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*]
 
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
 
355
  *Effects:* Invokes `swap` on the stored pointers and on the stored
356
  deleters of `*this` and `u`.
357