From Jason Turner

[optional.assign]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpj1un7pnk/{from.md → to.md} +47 -63
tmp/tmpj1un7pnk/{from.md → to.md} RENAMED
@@ -1,9 +1,9 @@
1
  #### Assignment <a id="optional.assign">[[optional.assign]]</a>
2
 
3
  ``` cpp
4
- 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
 
@@ -18,22 +18,22 @@ constexpr optional<T>& operator=(const optional& rhs);
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> &&`
@@ -46,161 +46,146 @@ constexpr optional& operator=(optional&& rhs) noexcept(see below);
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
  ```
70
 
71
- If any exception is thrown, the result of the expression `bool(*this)`
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`,
116
- - `is_constructible_v<T, const optional<U>&>` is `false`,
117
- - `is_constructible_v<T, const optional<U>&&>` is `false`,
118
- - `is_convertible_v<optional<U>&, T>` is `false`,
119
- - `is_convertible_v<optional<U>&&, T>` is `false`,
120
- - `is_convertible_v<const optional<U>&, T>` is `false`,
121
- - `is_convertible_v<const optional<U>&&, T>` 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`,
159
- - `is_constructible_v<T, const optional<U>&>` is `false`,
160
- - `is_constructible_v<T, const optional<U>&&>` is `false`,
161
- - `is_convertible_v<optional<U>&, T>` is `false`,
162
- - `is_convertible_v<optional<U>&&, T>` is `false`,
163
- - `is_convertible_v<const optional<U>&, T>` is `false`,
164
- - `is_convertible_v<const optional<U>&&, T>` 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
 
@@ -209,19 +194,18 @@ arguments `std::forward<Args>(args)...`.
209
  *Remarks:* If an exception is thrown during the call to `T`’s
210
  constructor, `*this` does not contain a value, and the previous `*val`
211
  (if any) has been destroyed.
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
 
 
1
  #### Assignment <a id="optional.assign">[[optional.assign]]</a>
2
 
3
  ``` cpp
4
+ constexpr 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
 
 
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 | direct-non-list-initializes the contained value with `*rhs` |
25
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
26
 
27
 
28
+ *Ensures:* `rhs.has_value() == this->has_value()`.
29
 
30
  *Returns:* `*this`.
31
 
32
  *Remarks:* If any exception is thrown, the result of the expression
33
+ `this->has_value()` remains unchanged. If an exception is thrown during
34
+ the 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> &&`
 
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
+ `rhs.has_value()` 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 | direct-non-list-initializes the contained value 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:* `rhs.has_value() == this->has_value()`.
62
 
63
  *Returns:* `*this`.
64
 
65
+ *Remarks:* The exception specification is equivalent to:
66
 
67
  ``` cpp
68
  is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
69
  ```
70
 
71
+ If any exception is thrown, the result of the expression
72
+ `this->has_value()` remains unchanged. If an exception is thrown during
73
+ the call to `T`’s move constructor, the state of `*rhs.val` is
74
+ determined by the exception safety guarantee of `T`’s move constructor.
75
+ If an exception is thrown during the call to `T`’s move assignment, the
76
+ state of `*val` and `*rhs.val` is determined by the exception safety
77
+ guarantee of `T`’s move assignment. If
78
+ `is_trivially_move_constructible_v<T> &&`
79
  `is_trivially_move_assignable_v<T> &&` `is_trivially_destructible_v<T>`
80
  is `true`, this assignment operator is trivial.
81
 
82
  ``` cpp
83
+ template<class U = T> constexpr optional<T>& operator=(U&& v);
84
  ```
85
 
86
  *Constraints:* `is_same_v<remove_cvref_t<U>, optional>` is `false`,
87
  `conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
88
  `is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
89
  `true`.
90
 
91
  *Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
92
+ the contained value; otherwise direct-non-list-initializes the contained
93
+ value with `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
+ `this->has_value()` remains unchanged. If an exception is thrown during
101
+ the 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> constexpr 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
+ - *`converts-from-any-cvref`*`<T, optional<U>>` is `false`,
 
 
 
 
 
 
 
115
  - `is_assignable_v<T&, optional<U>&>` is `false`,
116
  - `is_assignable_v<T&, optional<U>&&>` is `false`,
117
  - `is_assignable_v<T&, const optional<U>&>` is `false`, and
118
  - `is_assignable_v<T&, const optional<U>&&>` is `false`.
119
 
120
  *Effects:* See [[optional.assign.copy.templ]].
121
 
122
  **Table: `optional::operator=(const optional<U>&)` effects** <a id="optional.assign.copy.templ">[optional.assign.copy.templ]</a>
123
 
124
  | | `*this` contains a value | `*this` does not contain a value |
125
+ | ------------------------------ | ------------------------------------------------------ | ----------------------------------------------------------- |
126
+ | `rhs` contains a value | assigns `*rhs` to the contained value | direct-non-list-initializes the contained value with `*rhs` |
127
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
128
 
129
 
130
+ *Ensures:* `rhs.has_value() == this->has_value()`.
131
 
132
  *Returns:* `*this`.
133
 
134
  *Remarks:* If any exception is thrown, the result of the expression
135
+ `this->has_value()` remains unchanged. If an exception is thrown during
136
+ the call to `T`’s constructor, the state of `*rhs.val` is determined by
137
+ the exception safety guarantee of `T`’s constructor. If an exception is
138
  thrown during the call to `T`’s assignment, the state of `*val` and
139
  `*rhs.val` is determined by the exception safety guarantee of `T`’s
140
  assignment.
141
 
142
  ``` cpp
143
+ template<class U> constexpr optional<T>& operator=(optional<U>&& rhs);
144
  ```
145
 
146
  *Constraints:*
147
 
148
  - `is_constructible_v<T, U>` is `true`,
149
  - `is_assignable_v<T&, U>` is `true`,
150
+ - *`converts-from-any-cvref`*`<T, optional<U>>` is `false`,
 
 
 
 
 
 
 
151
  - `is_assignable_v<T&, optional<U>&>` is `false`,
152
  - `is_assignable_v<T&, optional<U>&&>` is `false`,
153
  - `is_assignable_v<T&, const optional<U>&>` is `false`, and
154
  - `is_assignable_v<T&, const optional<U>&&>` is `false`.
155
 
156
  *Effects:* See [[optional.assign.move.templ]]. The result of the
157
+ expression `rhs.has_value()` remains unchanged.
158
 
159
  **Table: `optional::operator=(optional<U>&&)` effects** <a id="optional.assign.move.templ">[optional.assign.move.templ]</a>
160
 
161
  | | `*this` contains a value | `*this` does not contain a value |
162
+ | ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------- |
163
+ | `rhs` contains a value | assigns `std::move(*rhs)` to the contained value | direct-non-list-initializes the contained value with `std::move(*rhs)` |
164
  | `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
165
 
166
 
167
+ *Ensures:* `rhs.has_value() == this->has_value()`.
168
 
169
  *Returns:* `*this`.
170
 
171
  *Remarks:* If any exception is thrown, the result of the expression
172
+ `this->has_value()` remains unchanged. If an exception is thrown during
173
+ the call to `T`’s constructor, the state of `*rhs.val` is determined by
174
+ the exception safety guarantee of `T`’s constructor. If an exception is
175
  thrown during the call to `T`’s assignment, the state of `*val` and
176
  `*rhs.val` is determined by the exception safety guarantee of `T`’s
177
  assignment.
178
 
179
  ``` cpp
180
+ template<class... Args> constexpr T& emplace(Args&&... args);
181
  ```
182
 
183
  *Mandates:* `is_constructible_v<T, Args...>` is `true`.
184
 
185
+ *Effects:* Calls `*this = nullopt`. Then direct-non-list-initializes the
186
+ contained value with `std::forward<Args>(args)...`.
 
187
 
188
  *Ensures:* `*this` contains a value.
189
 
190
  *Returns:* A reference to the new contained value.
191
 
 
194
  *Remarks:* If an exception is thrown during the call to `T`’s
195
  constructor, `*this` does not contain a value, and the previous `*val`
196
  (if any) has been destroyed.
197
 
198
  ``` cpp
199
+ template<class U, class... Args> constexpr T& emplace(initializer_list<U> il, Args&&... args);
200
  ```
201
 
202
  *Constraints:* `is_constructible_v<T, initializer_list<U>&, Args...>` is
203
  `true`.
204
 
205
+ *Effects:* Calls `*this = nullopt`. Then direct-non-list-initializes the
206
+ contained value with `il, std::forward<Args>(args)...`.
 
207
 
208
  *Ensures:* `*this` contains a value.
209
 
210
  *Returns:* A reference to the new contained value.
211