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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Class template `optional` <a id="optional.optional">[[optional.optional]]</a>
|
| 2 |
+
|
| 3 |
+
``` cpp
|
| 4 |
+
template <class T>
|
| 5 |
+
class optional {
|
| 6 |
+
public:
|
| 7 |
+
using value_type = T;
|
| 8 |
+
|
| 9 |
+
// [optional.ctor], constructors
|
| 10 |
+
constexpr optional() noexcept;
|
| 11 |
+
constexpr optional(nullopt_t) noexcept;
|
| 12 |
+
constexpr optional(const optional&);
|
| 13 |
+
constexpr optional(optional&&) noexcept(see below);
|
| 14 |
+
template <class... Args>
|
| 15 |
+
constexpr explicit optional(in_place_t, Args&&...);
|
| 16 |
+
template <class U, class... Args>
|
| 17 |
+
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
| 18 |
+
template <class U = T>
|
| 19 |
+
\EXPLICIT constexpr optional(U&&);
|
| 20 |
+
template <class U>
|
| 21 |
+
\EXPLICIT optional(const optional<U>&);
|
| 22 |
+
template <class U>
|
| 23 |
+
\EXPLICIT optional(optional<U>&&);
|
| 24 |
+
|
| 25 |
+
// [optional.dtor], destructor
|
| 26 |
+
~optional();
|
| 27 |
+
|
| 28 |
+
// [optional.assign], assignment
|
| 29 |
+
optional& operator=(nullopt_t) noexcept;
|
| 30 |
+
optional& operator=(const optional&);
|
| 31 |
+
optional& operator=(optional&&) noexcept(see below);
|
| 32 |
+
template <class U = T> optional& operator=(U&&);
|
| 33 |
+
template <class U> optional& operator=(const optional<U>&);
|
| 34 |
+
template <class U> optional& operator=(optional<U>&&);
|
| 35 |
+
template <class... Args> T& emplace(Args&&...);
|
| 36 |
+
template <class U, class... Args> T& emplace(initializer_list<U>, Args&&...);
|
| 37 |
+
|
| 38 |
+
// [optional.swap], swap
|
| 39 |
+
void swap(optional&) noexcept(see below);
|
| 40 |
+
|
| 41 |
+
// [optional.observe], observers
|
| 42 |
+
constexpr const T* operator->() const;
|
| 43 |
+
constexpr T* operator->();
|
| 44 |
+
constexpr const T& operator*() const&;
|
| 45 |
+
constexpr T& operator*() &;
|
| 46 |
+
constexpr T&& operator*() &&;
|
| 47 |
+
constexpr const T&& operator*() const&&;
|
| 48 |
+
constexpr explicit operator bool() const noexcept;
|
| 49 |
+
constexpr bool has_value() const noexcept;
|
| 50 |
+
constexpr const T& value() const&;
|
| 51 |
+
constexpr T& value() &;
|
| 52 |
+
constexpr T&& value() &&;
|
| 53 |
+
constexpr const T&& value() const&&;
|
| 54 |
+
template <class U> constexpr T value_or(U&&) const&;
|
| 55 |
+
template <class U> constexpr T value_or(U&&) &&;
|
| 56 |
+
|
| 57 |
+
// [optional.mod], modifiers
|
| 58 |
+
void reset() noexcept;
|
| 59 |
+
|
| 60 |
+
private:
|
| 61 |
+
T *val; // exposition only
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
template<class T> optional(T) -> optional<T>;
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
Any instance of `optional<T>` at any given time either contains a value
|
| 68 |
+
or does not contain a value. When an instance of `optional<T>` *contains
|
| 69 |
+
a value*, it means that an object of type `T`, referred to as the
|
| 70 |
+
optional object’s *contained value*, is allocated within the storage of
|
| 71 |
+
the optional object. Implementations are not permitted to use additional
|
| 72 |
+
storage, such as dynamic memory, to allocate its contained value. The
|
| 73 |
+
contained value shall be allocated in a region of the `optional<T>`
|
| 74 |
+
storage suitably aligned for the type `T`. When an object of type
|
| 75 |
+
`optional<T>` is contextually converted to `bool`, the conversion
|
| 76 |
+
returns `true` if the object contains a value; otherwise the conversion
|
| 77 |
+
returns `false`.
|
| 78 |
+
|
| 79 |
+
Member `val` is provided for exposition only. When an `optional<T>`
|
| 80 |
+
object contains a value, `val` points to the contained value.
|
| 81 |
+
|
| 82 |
+
`T` shall be an object type and shall satisfy the requirements of
|
| 83 |
+
`Destructible` (Table [[tab:destructible]]).
|
| 84 |
+
|
| 85 |
+
#### Constructors <a id="optional.ctor">[[optional.ctor]]</a>
|
| 86 |
+
|
| 87 |
+
``` cpp
|
| 88 |
+
constexpr optional() noexcept;
|
| 89 |
+
constexpr optional(nullopt_t) noexcept;
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
*Postconditions:* `*this` does not contain a value.
|
| 93 |
+
|
| 94 |
+
*Remarks:* No contained value is initialized. For every object type `T`
|
| 95 |
+
these constructors shall be constexpr constructors ([[dcl.constexpr]]).
|
| 96 |
+
|
| 97 |
+
``` cpp
|
| 98 |
+
constexpr optional(const optional& rhs);
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 102 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 103 |
+
expression `*rhs`.
|
| 104 |
+
|
| 105 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 106 |
+
|
| 107 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 108 |
+
|
| 109 |
+
*Remarks:* This constructor shall be defined as deleted unless
|
| 110 |
+
`is_copy_constructible_v<T>` is `true`. If
|
| 111 |
+
`is_trivially_copy_constructible_v<T>` is `true`, this constructor shall
|
| 112 |
+
be a `constexpr` constructor.
|
| 113 |
+
|
| 114 |
+
``` cpp
|
| 115 |
+
constexpr optional(optional&& rhs) noexcept(see below);
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 119 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 120 |
+
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 121 |
+
|
| 122 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 123 |
+
|
| 124 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 125 |
+
|
| 126 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
| 127 |
+
`is_nothrow_move_constructible_v<T>`. This constructor shall not
|
| 128 |
+
participate in overload resolution unless `is_move_constructible_v<T>`
|
| 129 |
+
is `true`. If `is_trivially_move_constructible_v<T>` is `true`, this
|
| 130 |
+
constructor shall be a `constexpr` constructor.
|
| 131 |
+
|
| 132 |
+
``` cpp
|
| 133 |
+
template <class... Args> constexpr explicit optional(in_place_t, Args&&... args);
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
*Effects:* Initializes the contained value as if
|
| 137 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 138 |
+
`std::forward<Args>(args)...`.
|
| 139 |
+
|
| 140 |
+
*Postconditions:* `*this` contains a value.
|
| 141 |
+
|
| 142 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 143 |
+
|
| 144 |
+
*Remarks:* If `T`’s constructor selected for the initialization is a
|
| 145 |
+
constexpr constructor, this constructor shall be a constexpr
|
| 146 |
+
constructor. This constructor shall not participate in overload
|
| 147 |
+
resolution unless `is_constructible_v<T, Args...>` is `true`.
|
| 148 |
+
|
| 149 |
+
``` cpp
|
| 150 |
+
template <class U, class... Args>
|
| 151 |
+
constexpr explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
*Effects:* Initializes the contained value as if
|
| 155 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 156 |
+
`il, std::forward<Args>(args)...`.
|
| 157 |
+
|
| 158 |
+
*Postconditions:* `*this` contains a value.
|
| 159 |
+
|
| 160 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 161 |
+
|
| 162 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 163 |
+
unless `is_constructible_v<T, initializer_list<U>&, Args&&...>` is
|
| 164 |
+
`true`. If `T`’s constructor selected for the initialization is a
|
| 165 |
+
constexpr constructor, this constructor shall be a constexpr
|
| 166 |
+
constructor.
|
| 167 |
+
|
| 168 |
+
[*Note 1*: The following constructors are conditionally specified as
|
| 169 |
+
explicit. This is typically implemented by declaring two such
|
| 170 |
+
constructors, of which at most one participates in overload
|
| 171 |
+
resolution. — *end note*]
|
| 172 |
+
|
| 173 |
+
``` cpp
|
| 174 |
+
template <class U = T> \EXPLICIT constexpr optional(U&& v);
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
*Effects:* Initializes the contained value as if
|
| 178 |
+
direct-non-list-initializing an object of type `T` with the expression
|
| 179 |
+
`std::forward<U>(v)`.
|
| 180 |
+
|
| 181 |
+
*Postconditions:* `*this` contains a value.
|
| 182 |
+
|
| 183 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 184 |
+
|
| 185 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 186 |
+
this constructor shall be a constexpr constructor. This constructor
|
| 187 |
+
shall not participate in overload resolution unless
|
| 188 |
+
`is_constructible_v<T, U&&>` is `true`,
|
| 189 |
+
`is_same_v<decay_t<U>, in_place_t>` is `false`, and
|
| 190 |
+
`is_same_v<optional<T>, decay_t<U>>` is `false`. The constructor is
|
| 191 |
+
explicit if and only if `is_convertible_v<U&&, T>` is `false`.
|
| 192 |
+
|
| 193 |
+
``` cpp
|
| 194 |
+
template <class U> \EXPLICIT optional(const optional<U>& rhs);
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 198 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 199 |
+
expression `*rhs`.
|
| 200 |
+
|
| 201 |
+
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 202 |
+
|
| 203 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 204 |
+
|
| 205 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 206 |
+
unless
|
| 207 |
+
|
| 208 |
+
- `is_constructible_v<T, const U&>` is `true`,
|
| 209 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 210 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 211 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 212 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 213 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 214 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 215 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 216 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 217 |
+
|
| 218 |
+
The constructor is explicit if and only if
|
| 219 |
+
`is_convertible_v<const U&, T>` is `false`.
|
| 220 |
+
|
| 221 |
+
``` cpp
|
| 222 |
+
template <class U> \EXPLICIT optional(optional<U>&& rhs);
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 226 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 227 |
+
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 228 |
+
|
| 229 |
+
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 230 |
+
|
| 231 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 232 |
+
|
| 233 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 234 |
+
unless
|
| 235 |
+
|
| 236 |
+
- `is_constructible_v<T, U&&>` is true,
|
| 237 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 238 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 239 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 240 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 241 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 242 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 243 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 244 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 245 |
+
|
| 246 |
+
The constructor is explicit if and only if `is_convertible_v<U&&, T>` is
|
| 247 |
+
`false`.
|
| 248 |
+
|
| 249 |
+
#### Destructor <a id="optional.dtor">[[optional.dtor]]</a>
|
| 250 |
+
|
| 251 |
+
``` cpp
|
| 252 |
+
~optional();
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
*Effects:* If `is_trivially_destructible_v<T> != true` and `*this`
|
| 256 |
+
contains a value, calls
|
| 257 |
+
|
| 258 |
+
``` cpp
|
| 259 |
+
val->T::~T()
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
*Remarks:* If `is_trivially_destructible_v<T> == true` then this
|
| 263 |
+
destructor shall be a trivial destructor.
|
| 264 |
+
|
| 265 |
+
#### Assignment <a id="optional.assign">[[optional.assign]]</a>
|
| 266 |
+
|
| 267 |
+
``` cpp
|
| 268 |
+
optional<T>& operator=(nullopt_t) noexcept;
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 272 |
+
the contained value; otherwise no effect.
|
| 273 |
+
|
| 274 |
+
*Returns:* `*this`.
|
| 275 |
+
|
| 276 |
+
*Postconditions:* `*this` does not contain a value.
|
| 277 |
+
|
| 278 |
+
``` cpp
|
| 279 |
+
optional<T>& operator=(const optional& rhs);
|
| 280 |
+
```
|
| 281 |
+
|
| 282 |
+
*Effects:* See Table [[tab:optional.assign.copy]].
|
| 283 |
+
|
| 284 |
+
**Table: `optional::operator=(const optional&)` effects** <a id="tab:optional.assign.copy">[tab:optional.assign.copy]</a>
|
| 285 |
+
|
| 286 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 287 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 288 |
+
| `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` |
|
| 289 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
*Returns:* `*this`.
|
| 293 |
+
|
| 294 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 295 |
+
|
| 296 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 297 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 298 |
+
call to `T`’s copy constructor, no effect. If an exception is thrown
|
| 299 |
+
during the call to `T`’s copy assignment, the state of its contained
|
| 300 |
+
value is as defined by the exception safety guarantee of `T`’s copy
|
| 301 |
+
assignment. This operator shall be defined as deleted unless
|
| 302 |
+
`is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
|
| 303 |
+
`true`.
|
| 304 |
+
|
| 305 |
+
``` cpp
|
| 306 |
+
optional<T>& operator=(optional&& rhs) noexcept(see below);
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
*Effects:* See Table [[tab:optional.assign.move]]. The result of the
|
| 310 |
+
expression `bool(rhs)` remains unchanged.
|
| 311 |
+
|
| 312 |
+
**Table: `optional::operator=(optional&&)` effects** <a id="tab:optional.assign.move">[tab:optional.assign.move]</a>
|
| 313 |
+
|
| 314 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 315 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 316 |
+
| `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)` |
|
| 317 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
*Returns:* `*this`.
|
| 321 |
+
|
| 322 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 323 |
+
|
| 324 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 325 |
+
|
| 326 |
+
``` cpp
|
| 327 |
+
is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
|
| 328 |
+
```
|
| 329 |
+
|
| 330 |
+
If any exception is thrown, the result of the expression `bool(*this)`
|
| 331 |
+
remains unchanged. If an exception is thrown during the call to `T`’s
|
| 332 |
+
move constructor, the state of `*rhs.val` is determined by the exception
|
| 333 |
+
safety guarantee of `T`’s move constructor. If an exception is thrown
|
| 334 |
+
during the call to `T`’s move assignment, the state of `*val` and
|
| 335 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s move
|
| 336 |
+
assignment. This operator shall not participate in overload resolution
|
| 337 |
+
unless `is_move_constructible_v<T>` is `true` and
|
| 338 |
+
`is_move_assignable_v<T>` is `true`.
|
| 339 |
+
|
| 340 |
+
``` cpp
|
| 341 |
+
template <class U = T> optional<T>& operator=(U&& v);
|
| 342 |
+
```
|
| 343 |
+
|
| 344 |
+
*Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
|
| 345 |
+
the contained value; otherwise initializes the contained value as if
|
| 346 |
+
direct-non-list-initializing object of type `T` with
|
| 347 |
+
`std::forward<U>(v)`.
|
| 348 |
+
|
| 349 |
+
*Returns:* `*this`.
|
| 350 |
+
|
| 351 |
+
*Postconditions:* `*this` contains a value.
|
| 352 |
+
|
| 353 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 354 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 355 |
+
call to `T`’s constructor, the state of `v` is determined by the
|
| 356 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 357 |
+
thrown during the call to `T`’s assignment, the state of `*val` and `v`
|
| 358 |
+
is determined by the exception safety guarantee of `T`’s assignment.
|
| 359 |
+
This function shall not participate in overload resolution unless
|
| 360 |
+
`is_same_v<optional<T>, decay_t<U>>` is `false`,
|
| 361 |
+
`conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
|
| 362 |
+
`is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
|
| 363 |
+
`true`.
|
| 364 |
+
|
| 365 |
+
``` cpp
|
| 366 |
+
template <class U> optional<T>& operator=(const optional<U>& rhs);
|
| 367 |
+
```
|
| 368 |
+
|
| 369 |
+
*Effects:* See Table [[tab:optional.assign.copy.templ]].
|
| 370 |
+
|
| 371 |
+
**Table: `optional::operator=(const optional<U>&)` effects** <a id="tab:optional.assign.copy.templ">[tab:optional.assign.copy.templ]</a>
|
| 372 |
+
|
| 373 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 374 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 375 |
+
| `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` |
|
| 376 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
*Returns:* `*this`.
|
| 380 |
+
|
| 381 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 382 |
+
|
| 383 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 384 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 385 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 386 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 387 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 388 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 389 |
+
assignment. This function shall not participate in overload resolution
|
| 390 |
+
unless
|
| 391 |
+
|
| 392 |
+
- `is_constructible_v<T, const U&>` is `true`,
|
| 393 |
+
- `is_assignable_v<T&, const U&>` is `true`,
|
| 394 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 395 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 396 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 397 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 398 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 399 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 400 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`,
|
| 401 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`,
|
| 402 |
+
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 403 |
+
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 404 |
+
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 405 |
+
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 406 |
+
|
| 407 |
+
``` cpp
|
| 408 |
+
template <class U> optional<T>& operator=(optional<U>&& rhs);
|
| 409 |
+
```
|
| 410 |
+
|
| 411 |
+
*Effects:* See Table [[tab:optional.assign.move.templ]]. The result of
|
| 412 |
+
the expression `bool(rhs)` remains unchanged.
|
| 413 |
+
|
| 414 |
+
**Table: `optional::operator=(optional<U>&&)` effects** <a id="tab:optional.assign.move.templ">[tab:optional.assign.move.templ]</a>
|
| 415 |
+
|
| 416 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 417 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 418 |
+
| `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)` |
|
| 419 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
*Returns:* `*this`.
|
| 423 |
+
|
| 424 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 425 |
+
|
| 426 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 427 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 428 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 429 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 430 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 431 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 432 |
+
assignment. This function shall not participate in overload resolution
|
| 433 |
+
unless
|
| 434 |
+
|
| 435 |
+
- `is_constructible_v<T, U>` is `true`,
|
| 436 |
+
- `is_assignable_v<T&, U>` is `true`,
|
| 437 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 438 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 439 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 440 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 441 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 442 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 443 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`,
|
| 444 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`,
|
| 445 |
+
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 446 |
+
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 447 |
+
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 448 |
+
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 449 |
+
|
| 450 |
+
``` cpp
|
| 451 |
+
template <class... Args> T& emplace(Args&&... args);
|
| 452 |
+
```
|
| 453 |
+
|
| 454 |
+
*Requires:* `is_constructible_v<T, Args&&...>` is `true`.
|
| 455 |
+
|
| 456 |
+
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 457 |
+
as if direct-non-list-initializing an object of type `T` with the
|
| 458 |
+
arguments `std::forward<Args>(args)...`.
|
| 459 |
+
|
| 460 |
+
*Postconditions:* `*this` contains a value.
|
| 461 |
+
|
| 462 |
+
*Returns:* A reference to the new contained value.
|
| 463 |
+
|
| 464 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 465 |
+
|
| 466 |
+
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 467 |
+
constructor, `*this` does not contain a value, and the previous `*val`
|
| 468 |
+
(if any) has been destroyed.
|
| 469 |
+
|
| 470 |
+
``` cpp
|
| 471 |
+
template <class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 472 |
+
```
|
| 473 |
+
|
| 474 |
+
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 475 |
+
as if direct-non-list-initializing an object of type `T` with the
|
| 476 |
+
arguments `il, std::forward<Args>(args)...`.
|
| 477 |
+
|
| 478 |
+
*Postconditions:* `*this` contains a value.
|
| 479 |
+
|
| 480 |
+
*Returns:* A reference to the new contained value.
|
| 481 |
+
|
| 482 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 483 |
+
|
| 484 |
+
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 485 |
+
constructor, `*this` does not contain a value, and the previous `*val`
|
| 486 |
+
(if any) has been destroyed. This function shall not participate in
|
| 487 |
+
overload resolution unless
|
| 488 |
+
`is_constructible_v<T, initializer_list<U>&, Args&&...>` is `true`.
|
| 489 |
+
|
| 490 |
+
#### Swap <a id="optional.swap">[[optional.swap]]</a>
|
| 491 |
+
|
| 492 |
+
``` cpp
|
| 493 |
+
void swap(optional& rhs) noexcept(see below);
|
| 494 |
+
```
|
| 495 |
+
|
| 496 |
+
*Requires:* Lvalues of type `T` shall be swappable and
|
| 497 |
+
`is_move_constructible_v<T>` is `true`.
|
| 498 |
+
|
| 499 |
+
*Effects:* See Table [[tab:optional.swap]].
|
| 500 |
+
|
| 501 |
+
**Table: `optional::swap(optional&)` effects** <a id="tab:optional.swap">[tab:optional.swap]</a>
|
| 502 |
+
|
| 503 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 504 |
+
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 505 |
+
| `rhs` contains a value | calls `swap(*(*this), *rhs)` | initializes the contained value of `*this` as if direct-non-list-initializing an object of type `T` with the expression `std::move(*rhs)`, followed by `rhs.val->T::~T()`; postcondition is that `*this` contains a value and `rhs` does not contain a value |
|
| 506 |
+
| `rhs` does not contain a value | initializes the contained value of `rhs` as if direct-non-list-initializing an object of type `T` with the expression `std::move(*(*this))`, followed by `val->T::~T()`; postcondition is that `*this` does not contain a value and `rhs` contains a value | no effect |
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
*Throws:* Any exceptions thrown by the operations in the relevant part
|
| 510 |
+
of Table [[tab:optional.swap]].
|
| 511 |
+
|
| 512 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 513 |
+
|
| 514 |
+
``` cpp
|
| 515 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>
|
| 516 |
+
```
|
| 517 |
+
|
| 518 |
+
If any exception is thrown, the results of the expressions `bool(*this)`
|
| 519 |
+
and `bool(rhs)` remain unchanged. If an exception is thrown during the
|
| 520 |
+
call to function `swap`, the state of `*val` and `*rhs.val` is
|
| 521 |
+
determined by the exception safety guarantee of `swap` for lvalues of
|
| 522 |
+
`T`. If an exception is thrown during the call to `T`’s move
|
| 523 |
+
constructor, the state of `*val` and `*rhs.val` is determined by the
|
| 524 |
+
exception safety guarantee of `T`’s move constructor.
|
| 525 |
+
|
| 526 |
+
#### Observers <a id="optional.observe">[[optional.observe]]</a>
|
| 527 |
+
|
| 528 |
+
``` cpp
|
| 529 |
+
constexpr const T* operator->() const;
|
| 530 |
+
constexpr T* operator->();
|
| 531 |
+
```
|
| 532 |
+
|
| 533 |
+
*Requires:* `*this` contains a value.
|
| 534 |
+
|
| 535 |
+
*Returns:* `val`.
|
| 536 |
+
|
| 537 |
+
*Throws:* Nothing.
|
| 538 |
+
|
| 539 |
+
*Remarks:* These functions shall be constexpr functions.
|
| 540 |
+
|
| 541 |
+
``` cpp
|
| 542 |
+
constexpr const T& operator*() const&;
|
| 543 |
+
constexpr T& operator*() &;
|
| 544 |
+
```
|
| 545 |
+
|
| 546 |
+
*Requires:* `*this` contains a value.
|
| 547 |
+
|
| 548 |
+
*Returns:* `*val`.
|
| 549 |
+
|
| 550 |
+
*Throws:* Nothing.
|
| 551 |
+
|
| 552 |
+
*Remarks:* These functions shall be constexpr functions.
|
| 553 |
+
|
| 554 |
+
``` cpp
|
| 555 |
+
constexpr T&& operator*() &&;
|
| 556 |
+
constexpr const T&& operator*() const&&;
|
| 557 |
+
```
|
| 558 |
+
|
| 559 |
+
*Requires:* `*this` contains a value.
|
| 560 |
+
|
| 561 |
+
*Effects:* Equivalent to: `return std::move(*val);`
|
| 562 |
+
|
| 563 |
+
``` cpp
|
| 564 |
+
constexpr explicit operator bool() const noexcept;
|
| 565 |
+
```
|
| 566 |
+
|
| 567 |
+
*Returns:* `true` if and only if `*this` contains a value.
|
| 568 |
+
|
| 569 |
+
*Remarks:* This function shall be a constexpr function.
|
| 570 |
+
|
| 571 |
+
``` cpp
|
| 572 |
+
constexpr bool has_value() const noexcept;
|
| 573 |
+
```
|
| 574 |
+
|
| 575 |
+
*Returns:* `true` if and only if `*this` contains a value.
|
| 576 |
+
|
| 577 |
+
*Remarks:* This function shall be a constexpr function.
|
| 578 |
+
|
| 579 |
+
``` cpp
|
| 580 |
+
constexpr const T& value() const&;
|
| 581 |
+
constexpr T& value() &;
|
| 582 |
+
```
|
| 583 |
+
|
| 584 |
+
*Effects:* Equivalent to:
|
| 585 |
+
|
| 586 |
+
``` cpp
|
| 587 |
+
return bool(*this) ? *val : throw bad_optional_access();
|
| 588 |
+
```
|
| 589 |
+
|
| 590 |
+
``` cpp
|
| 591 |
+
constexpr T&& value() &&;
|
| 592 |
+
constexpr const T&& value() const&&;
|
| 593 |
+
```
|
| 594 |
+
|
| 595 |
+
*Effects:* Equivalent to:
|
| 596 |
+
|
| 597 |
+
``` cpp
|
| 598 |
+
return bool(*this) ? std::move(*val) : throw bad_optional_access();
|
| 599 |
+
```
|
| 600 |
+
|
| 601 |
+
``` cpp
|
| 602 |
+
template <class U> constexpr T value_or(U&& v) const&;
|
| 603 |
+
```
|
| 604 |
+
|
| 605 |
+
*Effects:* Equivalent to:
|
| 606 |
+
|
| 607 |
+
``` cpp
|
| 608 |
+
return bool(*this) ? **this : static_cast<T>(std::forward<U>(v));
|
| 609 |
+
```
|
| 610 |
+
|
| 611 |
+
*Remarks:* If `is_copy_constructible_v<T> && is_convertible_v<U&&, T>`
|
| 612 |
+
is `false`, the program is ill-formed.
|
| 613 |
+
|
| 614 |
+
``` cpp
|
| 615 |
+
template <class U> constexpr T value_or(U&& v) &&;
|
| 616 |
+
```
|
| 617 |
+
|
| 618 |
+
*Effects:* Equivalent to:
|
| 619 |
+
|
| 620 |
+
``` cpp
|
| 621 |
+
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|
| 622 |
+
```
|
| 623 |
+
|
| 624 |
+
*Remarks:* If `is_move_constructible_v<T> && is_convertible_v<U&&, T>`
|
| 625 |
+
is `false`, the program is ill-formed.
|
| 626 |
+
|
| 627 |
+
#### Modifiers <a id="optional.mod">[[optional.mod]]</a>
|
| 628 |
+
|
| 629 |
+
``` cpp
|
| 630 |
+
void reset() noexcept;
|
| 631 |
+
```
|
| 632 |
+
|
| 633 |
+
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 634 |
+
the contained value; otherwise no effect.
|
| 635 |
+
|
| 636 |
+
*Postconditions:* `*this` does not contain a value.
|
| 637 |
+
|