From Jason Turner

[optional.assign]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpi807pxun/{from.md → to.md} +84 -76
tmp/tmpi807pxun/{from.md → to.md} RENAMED
@@ -5,60 +5,65 @@ optional<T>& operator=(nullopt_t) noexcept;
5
  ```
6
 
7
  *Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
8
  the contained value; otherwise no effect.
9
 
10
- *Returns:* `*this`.
11
 
12
- *Postconditions:* `*this` does not contain a value.
13
 
14
  ``` cpp
15
- optional<T>& operator=(const optional& rhs);
16
  ```
17
 
18
- *Effects:* See Table  [[tab:optional.assign.copy]].
19
 
20
- **Table: `optional::operator=(const optional&)` effects** <a id="tab:optional.assign.copy">[tab:optional.assign.copy]</a>
21
 
22
  | | `*this` contains a value | `*this` does not contain a value |
23
  | ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
24
  | `rhs` contains a value | assigns `*rhs` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `*rhs` |
25
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
26
 
27
 
28
- *Returns:* `*this`.
29
 
30
- *Postconditions:* `bool(rhs) == bool(*this)`.
31
 
32
  *Remarks:* If any exception is thrown, the result of the expression
33
  `bool(*this)` remains unchanged. If an exception is thrown during the
34
  call to `T`’s copy constructor, no effect. If an exception is thrown
35
  during the call to `T`’s copy assignment, the state of its contained
36
  value is as defined by the exception safety guarantee of `T`’s copy
37
- assignment. This operator shall be defined as deleted unless
38
  `is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
39
- `true`.
 
 
40
 
41
  ``` cpp
42
- optional<T>& operator=(optional&& rhs) noexcept(see below);
43
  ```
44
 
45
- *Effects:* See Table  [[tab:optional.assign.move]]. The result of the
46
- expression `bool(rhs)` remains unchanged.
47
 
48
- **Table: `optional::operator=(optional&&)` effects** <a id="tab:optional.assign.move">[tab:optional.assign.move]</a>
 
 
 
49
 
50
  | | `*this` contains a value | `*this` does not contain a value |
51
  | ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
52
  | `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `std::move(*rhs)` |
53
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
54
 
55
 
 
 
56
  *Returns:* `*this`.
57
 
58
- *Postconditions:* `bool(rhs) == bool(*this)`.
59
-
60
  *Remarks:* The expression inside `noexcept` is equivalent to:
61
 
62
  ``` cpp
63
  is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
64
  ```
@@ -67,65 +72,44 @@ If any exception is thrown, the result of the expression `bool(*this)`
67
  remains unchanged. If an exception is thrown during the call to `T`’s
68
  move constructor, the state of `*rhs.val` is determined by the exception
69
  safety guarantee of `T`’s move constructor. If an exception is thrown
70
  during the call to `T`’s move assignment, the state of `*val` and
71
  `*rhs.val` is determined by the exception safety guarantee of `T`’s move
72
- assignment. This operator shall not participate in overload resolution
73
- unless `is_move_constructible_v<T>` is `true` and
74
- `is_move_assignable_v<T>` is `true`.
75
 
76
  ``` cpp
77
  template<class U = T> optional<T>& operator=(U&& v);
78
  ```
79
 
 
 
 
 
 
80
  *Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
81
  the contained value; otherwise initializes the contained value as if
82
  direct-non-list-initializing object of type `T` with
83
  `std::forward<U>(v)`.
84
 
85
- *Returns:* `*this`.
86
 
87
- *Postconditions:* `*this` contains a value.
88
 
89
  *Remarks:* If any exception is thrown, the result of the expression
90
  `bool(*this)` remains unchanged. If an exception is thrown during the
91
  call to `T`’s constructor, the state of `v` is determined by the
92
  exception safety guarantee of `T`’s constructor. If an exception is
93
  thrown during the call to `T`’s assignment, the state of `*val` and `v`
94
  is determined by the exception safety guarantee of `T`’s assignment.
95
- This function shall not participate in overload resolution unless
96
- `is_same_v<optional<T>, decay_t<U>>` is `false`,
97
- `conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
98
- `is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
99
- `true`.
100
 
101
  ``` cpp
102
  template<class U> optional<T>& operator=(const optional<U>& rhs);
103
  ```
104
 
105
- *Effects:* See Table  [[tab:optional.assign.copy.templ]].
106
-
107
- **Table: `optional::operator=(const optional<U>&)` effects** <a id="tab:optional.assign.copy.templ">[tab:optional.assign.copy.templ]</a>
108
-
109
- | | `*this` contains a value | `*this` does not contain a value |
110
- | ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
111
- | `rhs` contains a value | assigns `*rhs` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `*rhs` |
112
- | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
113
-
114
-
115
- *Returns:* `*this`.
116
-
117
- *Postconditions:* `bool(rhs) == bool(*this)`.
118
-
119
- *Remarks:* If any exception is thrown, the result of the expression
120
- `bool(*this)` remains unchanged. If an exception is thrown during the
121
- call to `T`’s constructor, the state of `*rhs.val` is determined by the
122
- exception safety guarantee of `T`’s constructor. If an exception is
123
- thrown during the call to `T`’s assignment, the state of `*val` and
124
- `*rhs.val` is determined by the exception safety guarantee of `T`’s
125
- assignment. This function shall not participate in overload resolution
126
- unless
127
 
128
  - `is_constructible_v<T, const U&>` is `true`,
129
  - `is_assignable_v<T&, const U&>` is `true`,
130
  - `is_constructible_v<T, optional<U>&>` is `false`,
131
  - `is_constructible_v<T, optional<U>&&>` is `false`,
@@ -138,37 +122,37 @@ unless
138
  - `is_assignable_v<T&, optional<U>&>` is `false`,
139
  - `is_assignable_v<T&, optional<U>&&>` is `false`,
140
  - `is_assignable_v<T&, const optional<U>&>` is `false`, and
141
  - `is_assignable_v<T&, const optional<U>&&>` is `false`.
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  ``` cpp
144
  template<class U> optional<T>& operator=(optional<U>&& rhs);
145
  ```
146
 
147
- *Effects:* See Table  [[tab:optional.assign.move.templ]]. The result of
148
- the expression `bool(rhs)` remains unchanged.
149
-
150
- **Table: `optional::operator=(optional<U>&&)` effects** <a id="tab:optional.assign.move.templ">[tab:optional.assign.move.templ]</a>
151
-
152
- | | `*this` contains a value | `*this` does not contain a value |
153
- | ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
154
- | `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `std::move(*rhs)` |
155
- | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
156
-
157
-
158
- *Returns:* `*this`.
159
-
160
- *Postconditions:* `bool(rhs) == bool(*this)`.
161
-
162
- *Remarks:* If any exception is thrown, the result of the expression
163
- `bool(*this)` remains unchanged. If an exception is thrown during the
164
- call to `T`’s constructor, the state of `*rhs.val` is determined by the
165
- exception safety guarantee of `T`’s constructor. If an exception is
166
- thrown during the call to `T`’s assignment, the state of `*val` and
167
- `*rhs.val` is determined by the exception safety guarantee of `T`’s
168
- assignment. This function shall not participate in overload resolution
169
- unless
170
 
171
  - `is_constructible_v<T, U>` is `true`,
172
  - `is_assignable_v<T&, U>` is `true`,
173
  - `is_constructible_v<T, optional<U>&>` is `false`,
174
  - `is_constructible_v<T, optional<U>&&>` is `false`,
@@ -181,21 +165,44 @@ unless
181
  - `is_assignable_v<T&, optional<U>&>` is `false`,
182
  - `is_assignable_v<T&, optional<U>&&>` is `false`,
183
  - `is_assignable_v<T&, const optional<U>&>` is `false`, and
184
  - `is_assignable_v<T&, const optional<U>&&>` is `false`.
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  ``` cpp
187
  template<class... Args> T& emplace(Args&&... args);
188
  ```
189
 
190
- *Requires:* `is_constructible_v<T, Args&&...>` is `true`.
191
 
192
  *Effects:* Calls `*this = nullopt`. Then initializes the contained value
193
  as if direct-non-list-initializing an object of type `T` with the
194
  arguments `std::forward<Args>(args)...`.
195
 
196
- *Postconditions:* `*this` contains a value.
197
 
198
  *Returns:* A reference to the new contained value.
199
 
200
  *Throws:* Any exception thrown by the selected constructor of `T`.
201
 
@@ -205,21 +212,22 @@ constructor, `*this` does not contain a value, and the previous `*val`
205
 
206
  ``` cpp
207
  template<class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
208
  ```
209
 
 
 
 
210
  *Effects:* Calls `*this = nullopt`. Then initializes the contained value
211
  as if direct-non-list-initializing an object of type `T` with the
212
  arguments `il, std::forward<Args>(args)...`.
213
 
214
- *Postconditions:* `*this` contains a value.
215
 
216
  *Returns:* A reference to the new contained value.
217
 
218
  *Throws:* Any exception thrown by the selected constructor of `T`.
219
 
220
  *Remarks:* If an exception is thrown during the call to `T`’s
221
  constructor, `*this` does not contain a value, and the previous `*val`
222
- (if any) has been destroyed. This function shall not participate in
223
- overload resolution unless
224
- `is_constructible_v<T, initializer_list<U>&, Args&&...>` is `true`.
225
 
 
5
  ```
6
 
7
  *Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
8
  the contained value; otherwise no effect.
9
 
10
+ *Ensures:* `*this` does not contain a value.
11
 
12
+ *Returns:* `*this`.
13
 
14
  ``` cpp
15
+ constexpr optional<T>& operator=(const optional& rhs);
16
  ```
17
 
18
+ *Effects:* See [[optional.assign.copy]].
19
 
20
+ **Table: `optional::operator=(const optional&)` effects** <a id="optional.assign.copy">[optional.assign.copy]</a>
21
 
22
  | | `*this` contains a value | `*this` does not contain a value |
23
  | ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
24
  | `rhs` contains a value | assigns `*rhs` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `*rhs` |
25
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
26
 
27
 
28
+ *Ensures:* `bool(rhs) == bool(*this)`.
29
 
30
+ *Returns:* `*this`.
31
 
32
  *Remarks:* If any exception is thrown, the result of the expression
33
  `bool(*this)` remains unchanged. If an exception is thrown during the
34
  call to `T`’s copy constructor, no effect. If an exception is thrown
35
  during the call to `T`’s copy assignment, the state of its contained
36
  value is as defined by the exception safety guarantee of `T`’s copy
37
+ assignment. This operator is defined as deleted unless
38
  `is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
39
+ `true`. If `is_trivially_copy_constructible_v<T> &&`
40
+ `is_trivially_copy_assignable_v<T> &&` `is_trivially_destructible_v<T>`
41
+ is `true`, this assignment operator is trivial.
42
 
43
  ``` cpp
44
+ constexpr optional& operator=(optional&& rhs) noexcept(see below);
45
  ```
46
 
47
+ *Constraints:* `is_move_constructible_v<T>` is `true` and
48
+ `is_move_assignable_v<T>` is `true`.
49
 
50
+ *Effects:* See [[optional.assign.move]]. The result of the expression
51
+ `bool(rhs)` remains unchanged.
52
+
53
+ **Table: `optional::operator=(optional&&)` effects** <a id="optional.assign.move">[optional.assign.move]</a>
54
 
55
  | | `*this` contains a value | `*this` does not contain a value |
56
  | ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
57
  | `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `std::move(*rhs)` |
58
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
59
 
60
 
61
+ *Ensures:* `bool(rhs) == bool(*this)`.
62
+
63
  *Returns:* `*this`.
64
 
 
 
65
  *Remarks:* The expression inside `noexcept` is equivalent to:
66
 
67
  ``` cpp
68
  is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
69
  ```
 
72
  remains unchanged. If an exception is thrown during the call to `T`’s
73
  move constructor, the state of `*rhs.val` is determined by the exception
74
  safety guarantee of `T`’s move constructor. If an exception is thrown
75
  during the call to `T`’s move assignment, the state of `*val` and
76
  `*rhs.val` is determined by the exception safety guarantee of `T`’s move
77
+ assignment. If `is_trivially_move_constructible_v<T> &&`
78
+ `is_trivially_move_assignable_v<T> &&` `is_trivially_destructible_v<T>`
79
+ is `true`, this assignment operator is trivial.
80
 
81
  ``` cpp
82
  template<class U = T> optional<T>& operator=(U&& v);
83
  ```
84
 
85
+ *Constraints:* `is_same_v<remove_cvref_t<U>, optional>` is `false`,
86
+ `conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
87
+ `is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
88
+ `true`.
89
+
90
  *Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
91
  the contained value; otherwise initializes the contained value as if
92
  direct-non-list-initializing object of type `T` with
93
  `std::forward<U>(v)`.
94
 
95
+ *Ensures:* `*this` contains a value.
96
 
97
+ *Returns:* `*this`.
98
 
99
  *Remarks:* If any exception is thrown, the result of the expression
100
  `bool(*this)` remains unchanged. If an exception is thrown during the
101
  call to `T`’s constructor, the state of `v` is determined by the
102
  exception safety guarantee of `T`’s constructor. If an exception is
103
  thrown during the call to `T`’s assignment, the state of `*val` and `v`
104
  is determined by the exception safety guarantee of `T`’s assignment.
 
 
 
 
 
105
 
106
  ``` cpp
107
  template<class U> optional<T>& operator=(const optional<U>& rhs);
108
  ```
109
 
110
+ *Constraints:*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  - `is_constructible_v<T, const U&>` is `true`,
113
  - `is_assignable_v<T&, const U&>` is `true`,
114
  - `is_constructible_v<T, optional<U>&>` is `false`,
115
  - `is_constructible_v<T, optional<U>&&>` is `false`,
 
122
  - `is_assignable_v<T&, optional<U>&>` is `false`,
123
  - `is_assignable_v<T&, optional<U>&&>` is `false`,
124
  - `is_assignable_v<T&, const optional<U>&>` is `false`, and
125
  - `is_assignable_v<T&, const optional<U>&&>` is `false`.
126
 
127
+ *Effects:* See [[optional.assign.copy.templ]].
128
+
129
+ **Table: `optional::operator=(const optional<U>&)` effects** <a id="optional.assign.copy.templ">[optional.assign.copy.templ]</a>
130
+
131
+ | | `*this` contains a value | `*this` does not contain a value |
132
+ | ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
133
+ | `rhs` contains a value | assigns `*rhs` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `*rhs` |
134
+ | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
135
+
136
+
137
+ *Ensures:* `bool(rhs) == bool(*this)`.
138
+
139
+ *Returns:* `*this`.
140
+
141
+ *Remarks:* If any exception is thrown, the result of the expression
142
+ `bool(*this)` remains unchanged. If an exception is thrown during the
143
+ call to `T`’s constructor, the state of `*rhs.val` is determined by the
144
+ exception safety guarantee of `T`’s constructor. If an exception is
145
+ thrown during the call to `T`’s assignment, the state of `*val` and
146
+ `*rhs.val` is determined by the exception safety guarantee of `T`’s
147
+ assignment.
148
+
149
  ``` cpp
150
  template<class U> optional<T>& operator=(optional<U>&& rhs);
151
  ```
152
 
153
+ *Constraints:*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  - `is_constructible_v<T, U>` is `true`,
156
  - `is_assignable_v<T&, U>` is `true`,
157
  - `is_constructible_v<T, optional<U>&>` is `false`,
158
  - `is_constructible_v<T, optional<U>&&>` is `false`,
 
165
  - `is_assignable_v<T&, optional<U>&>` is `false`,
166
  - `is_assignable_v<T&, optional<U>&&>` is `false`,
167
  - `is_assignable_v<T&, const optional<U>&>` is `false`, and
168
  - `is_assignable_v<T&, const optional<U>&&>` is `false`.
169
 
170
+ *Effects:* See [[optional.assign.move.templ]]. The result of the
171
+ expression `bool(rhs)` remains unchanged.
172
+
173
+ **Table: `optional::operator=(optional<U>&&)` effects** <a id="optional.assign.move.templ">[optional.assign.move.templ]</a>
174
+
175
+ | | `*this` contains a value | `*this` does not contain a value |
176
+ | ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
177
+ | `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | initializes the contained value as if direct-non-list-initializing an object of type `T` with `std::move(*rhs)` |
178
+ | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
179
+
180
+
181
+ *Ensures:* `bool(rhs) == bool(*this)`.
182
+
183
+ *Returns:* `*this`.
184
+
185
+ *Remarks:* If any exception is thrown, the result of the expression
186
+ `bool(*this)` remains unchanged. If an exception is thrown during the
187
+ call to `T`’s constructor, the state of `*rhs.val` is determined by the
188
+ exception safety guarantee of `T`’s constructor. If an exception is
189
+ thrown during the call to `T`’s assignment, the state of `*val` and
190
+ `*rhs.val` is determined by the exception safety guarantee of `T`’s
191
+ assignment.
192
+
193
  ``` cpp
194
  template<class... Args> T& emplace(Args&&... args);
195
  ```
196
 
197
+ *Mandates:* `is_constructible_v<T, Args...>` is `true`.
198
 
199
  *Effects:* Calls `*this = nullopt`. Then initializes the contained value
200
  as if direct-non-list-initializing an object of type `T` with the
201
  arguments `std::forward<Args>(args)...`.
202
 
203
+ *Ensures:* `*this` contains a value.
204
 
205
  *Returns:* A reference to the new contained value.
206
 
207
  *Throws:* Any exception thrown by the selected constructor of `T`.
208
 
 
212
 
213
  ``` cpp
214
  template<class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
215
  ```
216
 
217
+ *Constraints:* `is_constructible_v<T, initializer_list<U>&, Args...>` is
218
+ `true`.
219
+
220
  *Effects:* Calls `*this = nullopt`. Then initializes the contained value
221
  as if direct-non-list-initializing an object of type `T` with the
222
  arguments `il, std::forward<Args>(args)...`.
223
 
224
+ *Ensures:* `*this` contains a value.
225
 
226
  *Returns:* A reference to the new contained value.
227
 
228
  *Throws:* Any exception thrown by the selected constructor of `T`.
229
 
230
  *Remarks:* If an exception is thrown during the call to `T`’s
231
  constructor, `*this` does not contain a value, and the previous `*val`
232
+ (if any) has been destroyed.
 
 
233