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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Optional objects <a id="optional">[[optional]]</a>
|
| 2 |
+
|
| 3 |
+
### In general <a id="optional.general">[[optional.general]]</a>
|
| 4 |
+
|
| 5 |
+
This subclause describes class template `optional` that represents
|
| 6 |
+
optional objects. An *optional object* is an object that contains the
|
| 7 |
+
storage for another object and manages the lifetime of this contained
|
| 8 |
+
object, if any. The contained object may be initialized after the
|
| 9 |
+
optional object has been initialized, and may be destroyed before the
|
| 10 |
+
optional object has been destroyed. The initialization state of the
|
| 11 |
+
contained object is tracked by the optional object.
|
| 12 |
+
|
| 13 |
+
### Header `<optional>` synopsis <a id="optional.syn">[[optional.syn]]</a>
|
| 14 |
+
|
| 15 |
+
``` cpp
|
| 16 |
+
namespace std {
|
| 17 |
+
// [optional.optional], class template optional
|
| 18 |
+
template <class T>
|
| 19 |
+
class optional;
|
| 20 |
+
|
| 21 |
+
// [optional.nullopt], no-value state indicator
|
| 22 |
+
struct nullopt_t{see below};
|
| 23 |
+
inline constexpr nullopt_t nullopt(unspecified);
|
| 24 |
+
|
| 25 |
+
// [optional.bad.access], class bad_optional_access
|
| 26 |
+
class bad_optional_access;
|
| 27 |
+
|
| 28 |
+
// [optional.relops], relational operators
|
| 29 |
+
template <class T, class U>
|
| 30 |
+
constexpr bool operator==(const optional<T>&, const optional<U>&);
|
| 31 |
+
template <class T, class U>
|
| 32 |
+
constexpr bool operator!=(const optional<T>&, const optional<U>&);
|
| 33 |
+
template <class T, class U>
|
| 34 |
+
constexpr bool operator<(const optional<T>&, const optional<U>&);
|
| 35 |
+
template <class T, class U>
|
| 36 |
+
constexpr bool operator>(const optional<T>&, const optional<U>&);
|
| 37 |
+
template <class T, class U>
|
| 38 |
+
constexpr bool operator<=(const optional<T>&, const optional<U>&);
|
| 39 |
+
template <class T, class U>
|
| 40 |
+
constexpr bool operator>=(const optional<T>&, const optional<U>&);
|
| 41 |
+
|
| 42 |
+
// [optional.nullops], comparison with nullopt
|
| 43 |
+
template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
|
| 44 |
+
template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
|
| 45 |
+
template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
|
| 46 |
+
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
|
| 47 |
+
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
|
| 48 |
+
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
|
| 49 |
+
template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
|
| 50 |
+
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
|
| 51 |
+
template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
|
| 52 |
+
template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
|
| 53 |
+
template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
|
| 54 |
+
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
|
| 55 |
+
|
| 56 |
+
// [optional.comp_with_t], comparison with T
|
| 57 |
+
template <class T, class U> constexpr bool operator==(const optional<T>&, const U&);
|
| 58 |
+
template <class T, class U> constexpr bool operator==(const U&, const optional<T>&);
|
| 59 |
+
template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
|
| 60 |
+
template <class T, class U> constexpr bool operator!=(const U&, const optional<T>&);
|
| 61 |
+
template <class T, class U> constexpr bool operator<(const optional<T>&, const U&);
|
| 62 |
+
template <class T, class U> constexpr bool operator<(const U&, const optional<T>&);
|
| 63 |
+
template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
|
| 64 |
+
template <class T, class U> constexpr bool operator<=(const U&, const optional<T>&);
|
| 65 |
+
template <class T, class U> constexpr bool operator>(const optional<T>&, const U&);
|
| 66 |
+
template <class T, class U> constexpr bool operator>(const U&, const optional<T>&);
|
| 67 |
+
template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
|
| 68 |
+
template <class T, class U> constexpr bool operator>=(const U&, const optional<T>&);
|
| 69 |
+
|
| 70 |
+
// [optional.specalg], specialized algorithms
|
| 71 |
+
template <class T>
|
| 72 |
+
void swap(optional<T>&, optional<T>&) noexcept(see below);
|
| 73 |
+
|
| 74 |
+
template <class T>
|
| 75 |
+
constexpr optional<see below> make_optional(T&&);
|
| 76 |
+
template <class T, class... Args>
|
| 77 |
+
constexpr optional<T> make_optional(Args&&... args);
|
| 78 |
+
template <class T, class U, class... Args>
|
| 79 |
+
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
|
| 80 |
+
|
| 81 |
+
// [optional.hash], hash support
|
| 82 |
+
template <class T> struct hash;
|
| 83 |
+
template <class T> struct hash<optional<T>>;
|
| 84 |
+
}
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
A program that necessitates the instantiation of template `optional` for
|
| 88 |
+
a reference type, or for possibly cv-qualified types `in_place_t` or
|
| 89 |
+
`nullopt_t` is ill-formed.
|
| 90 |
+
|
| 91 |
+
### Class template `optional` <a id="optional.optional">[[optional.optional]]</a>
|
| 92 |
+
|
| 93 |
+
``` cpp
|
| 94 |
+
template <class T>
|
| 95 |
+
class optional {
|
| 96 |
+
public:
|
| 97 |
+
using value_type = T;
|
| 98 |
+
|
| 99 |
+
// [optional.ctor], constructors
|
| 100 |
+
constexpr optional() noexcept;
|
| 101 |
+
constexpr optional(nullopt_t) noexcept;
|
| 102 |
+
constexpr optional(const optional&);
|
| 103 |
+
constexpr optional(optional&&) noexcept(see below);
|
| 104 |
+
template <class... Args>
|
| 105 |
+
constexpr explicit optional(in_place_t, Args&&...);
|
| 106 |
+
template <class U, class... Args>
|
| 107 |
+
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
| 108 |
+
template <class U = T>
|
| 109 |
+
\EXPLICIT constexpr optional(U&&);
|
| 110 |
+
template <class U>
|
| 111 |
+
\EXPLICIT optional(const optional<U>&);
|
| 112 |
+
template <class U>
|
| 113 |
+
\EXPLICIT optional(optional<U>&&);
|
| 114 |
+
|
| 115 |
+
// [optional.dtor], destructor
|
| 116 |
+
~optional();
|
| 117 |
+
|
| 118 |
+
// [optional.assign], assignment
|
| 119 |
+
optional& operator=(nullopt_t) noexcept;
|
| 120 |
+
optional& operator=(const optional&);
|
| 121 |
+
optional& operator=(optional&&) noexcept(see below);
|
| 122 |
+
template <class U = T> optional& operator=(U&&);
|
| 123 |
+
template <class U> optional& operator=(const optional<U>&);
|
| 124 |
+
template <class U> optional& operator=(optional<U>&&);
|
| 125 |
+
template <class... Args> T& emplace(Args&&...);
|
| 126 |
+
template <class U, class... Args> T& emplace(initializer_list<U>, Args&&...);
|
| 127 |
+
|
| 128 |
+
// [optional.swap], swap
|
| 129 |
+
void swap(optional&) noexcept(see below);
|
| 130 |
+
|
| 131 |
+
// [optional.observe], observers
|
| 132 |
+
constexpr const T* operator->() const;
|
| 133 |
+
constexpr T* operator->();
|
| 134 |
+
constexpr const T& operator*() const&;
|
| 135 |
+
constexpr T& operator*() &;
|
| 136 |
+
constexpr T&& operator*() &&;
|
| 137 |
+
constexpr const T&& operator*() const&&;
|
| 138 |
+
constexpr explicit operator bool() const noexcept;
|
| 139 |
+
constexpr bool has_value() const noexcept;
|
| 140 |
+
constexpr const T& value() const&;
|
| 141 |
+
constexpr T& value() &;
|
| 142 |
+
constexpr T&& value() &&;
|
| 143 |
+
constexpr const T&& value() const&&;
|
| 144 |
+
template <class U> constexpr T value_or(U&&) const&;
|
| 145 |
+
template <class U> constexpr T value_or(U&&) &&;
|
| 146 |
+
|
| 147 |
+
// [optional.mod], modifiers
|
| 148 |
+
void reset() noexcept;
|
| 149 |
+
|
| 150 |
+
private:
|
| 151 |
+
T *val; // exposition only
|
| 152 |
+
};
|
| 153 |
+
|
| 154 |
+
template<class T> optional(T) -> optional<T>;
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
Any instance of `optional<T>` at any given time either contains a value
|
| 158 |
+
or does not contain a value. When an instance of `optional<T>` *contains
|
| 159 |
+
a value*, it means that an object of type `T`, referred to as the
|
| 160 |
+
optional object’s *contained value*, is allocated within the storage of
|
| 161 |
+
the optional object. Implementations are not permitted to use additional
|
| 162 |
+
storage, such as dynamic memory, to allocate its contained value. The
|
| 163 |
+
contained value shall be allocated in a region of the `optional<T>`
|
| 164 |
+
storage suitably aligned for the type `T`. When an object of type
|
| 165 |
+
`optional<T>` is contextually converted to `bool`, the conversion
|
| 166 |
+
returns `true` if the object contains a value; otherwise the conversion
|
| 167 |
+
returns `false`.
|
| 168 |
+
|
| 169 |
+
Member `val` is provided for exposition only. When an `optional<T>`
|
| 170 |
+
object contains a value, `val` points to the contained value.
|
| 171 |
+
|
| 172 |
+
`T` shall be an object type and shall satisfy the requirements of
|
| 173 |
+
`Destructible` (Table [[tab:destructible]]).
|
| 174 |
+
|
| 175 |
+
#### Constructors <a id="optional.ctor">[[optional.ctor]]</a>
|
| 176 |
+
|
| 177 |
+
``` cpp
|
| 178 |
+
constexpr optional() noexcept;
|
| 179 |
+
constexpr optional(nullopt_t) noexcept;
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
*Postconditions:* `*this` does not contain a value.
|
| 183 |
+
|
| 184 |
+
*Remarks:* No contained value is initialized. For every object type `T`
|
| 185 |
+
these constructors shall be constexpr constructors ([[dcl.constexpr]]).
|
| 186 |
+
|
| 187 |
+
``` cpp
|
| 188 |
+
constexpr optional(const optional& rhs);
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 192 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 193 |
+
expression `*rhs`.
|
| 194 |
+
|
| 195 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 196 |
+
|
| 197 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 198 |
+
|
| 199 |
+
*Remarks:* This constructor shall be defined as deleted unless
|
| 200 |
+
`is_copy_constructible_v<T>` is `true`. If
|
| 201 |
+
`is_trivially_copy_constructible_v<T>` is `true`, this constructor shall
|
| 202 |
+
be a `constexpr` constructor.
|
| 203 |
+
|
| 204 |
+
``` cpp
|
| 205 |
+
constexpr optional(optional&& rhs) noexcept(see below);
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 209 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 210 |
+
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 211 |
+
|
| 212 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 213 |
+
|
| 214 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 215 |
+
|
| 216 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
| 217 |
+
`is_nothrow_move_constructible_v<T>`. This constructor shall not
|
| 218 |
+
participate in overload resolution unless `is_move_constructible_v<T>`
|
| 219 |
+
is `true`. If `is_trivially_move_constructible_v<T>` is `true`, this
|
| 220 |
+
constructor shall be a `constexpr` constructor.
|
| 221 |
+
|
| 222 |
+
``` cpp
|
| 223 |
+
template <class... Args> constexpr explicit optional(in_place_t, Args&&... args);
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
*Effects:* Initializes the contained value as if
|
| 227 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 228 |
+
`std::forward<Args>(args)...`.
|
| 229 |
+
|
| 230 |
+
*Postconditions:* `*this` contains a value.
|
| 231 |
+
|
| 232 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 233 |
+
|
| 234 |
+
*Remarks:* If `T`’s constructor selected for the initialization is a
|
| 235 |
+
constexpr constructor, this constructor shall be a constexpr
|
| 236 |
+
constructor. This constructor shall not participate in overload
|
| 237 |
+
resolution unless `is_constructible_v<T, Args...>` is `true`.
|
| 238 |
+
|
| 239 |
+
``` cpp
|
| 240 |
+
template <class U, class... Args>
|
| 241 |
+
constexpr explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
*Effects:* Initializes the contained value as if
|
| 245 |
+
direct-non-list-initializing an object of type `T` with the arguments
|
| 246 |
+
`il, std::forward<Args>(args)...`.
|
| 247 |
+
|
| 248 |
+
*Postconditions:* `*this` contains a value.
|
| 249 |
+
|
| 250 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 251 |
+
|
| 252 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 253 |
+
unless `is_constructible_v<T, initializer_list<U>&, Args&&...>` is
|
| 254 |
+
`true`. If `T`’s constructor selected for the initialization is a
|
| 255 |
+
constexpr constructor, this constructor shall be a constexpr
|
| 256 |
+
constructor.
|
| 257 |
+
|
| 258 |
+
[*Note 1*: The following constructors are conditionally specified as
|
| 259 |
+
explicit. This is typically implemented by declaring two such
|
| 260 |
+
constructors, of which at most one participates in overload
|
| 261 |
+
resolution. — *end note*]
|
| 262 |
+
|
| 263 |
+
``` cpp
|
| 264 |
+
template <class U = T> \EXPLICIT constexpr optional(U&& v);
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
*Effects:* Initializes the contained value as if
|
| 268 |
+
direct-non-list-initializing an object of type `T` with the expression
|
| 269 |
+
`std::forward<U>(v)`.
|
| 270 |
+
|
| 271 |
+
*Postconditions:* `*this` contains a value.
|
| 272 |
+
|
| 273 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 274 |
+
|
| 275 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 276 |
+
this constructor shall be a constexpr constructor. This constructor
|
| 277 |
+
shall not participate in overload resolution unless
|
| 278 |
+
`is_constructible_v<T, U&&>` is `true`,
|
| 279 |
+
`is_same_v<decay_t<U>, in_place_t>` is `false`, and
|
| 280 |
+
`is_same_v<optional<T>, decay_t<U>>` is `false`. The constructor is
|
| 281 |
+
explicit if and only if `is_convertible_v<U&&, T>` is `false`.
|
| 282 |
+
|
| 283 |
+
``` cpp
|
| 284 |
+
template <class U> \EXPLICIT optional(const optional<U>& rhs);
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 288 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 289 |
+
expression `*rhs`.
|
| 290 |
+
|
| 291 |
+
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 292 |
+
|
| 293 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 294 |
+
|
| 295 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 296 |
+
unless
|
| 297 |
+
|
| 298 |
+
- `is_constructible_v<T, const U&>` is `true`,
|
| 299 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 300 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 301 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 302 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 303 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 304 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 305 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 306 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 307 |
+
|
| 308 |
+
The constructor is explicit if and only if
|
| 309 |
+
`is_convertible_v<const U&, T>` is `false`.
|
| 310 |
+
|
| 311 |
+
``` cpp
|
| 312 |
+
template <class U> \EXPLICIT optional(optional<U>&& rhs);
|
| 313 |
+
```
|
| 314 |
+
|
| 315 |
+
*Effects:* If `rhs` contains a value, initializes the contained value as
|
| 316 |
+
if direct-non-list-initializing an object of type `T` with the
|
| 317 |
+
expression `std::move(*rhs)`. `bool(rhs)` is unchanged.
|
| 318 |
+
|
| 319 |
+
*Postconditions:* `bool(rhs)` == `bool(*this)`.
|
| 320 |
+
|
| 321 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 322 |
+
|
| 323 |
+
*Remarks:* This constructor shall not participate in overload resolution
|
| 324 |
+
unless
|
| 325 |
+
|
| 326 |
+
- `is_constructible_v<T, U&&>` is true,
|
| 327 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 328 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 329 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 330 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 331 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 332 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 333 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`, and
|
| 334 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`.
|
| 335 |
+
|
| 336 |
+
The constructor is explicit if and only if `is_convertible_v<U&&, T>` is
|
| 337 |
+
`false`.
|
| 338 |
+
|
| 339 |
+
#### Destructor <a id="optional.dtor">[[optional.dtor]]</a>
|
| 340 |
+
|
| 341 |
+
``` cpp
|
| 342 |
+
~optional();
|
| 343 |
+
```
|
| 344 |
+
|
| 345 |
+
*Effects:* If `is_trivially_destructible_v<T> != true` and `*this`
|
| 346 |
+
contains a value, calls
|
| 347 |
+
|
| 348 |
+
``` cpp
|
| 349 |
+
val->T::~T()
|
| 350 |
+
```
|
| 351 |
+
|
| 352 |
+
*Remarks:* If `is_trivially_destructible_v<T> == true` then this
|
| 353 |
+
destructor shall be a trivial destructor.
|
| 354 |
+
|
| 355 |
+
#### Assignment <a id="optional.assign">[[optional.assign]]</a>
|
| 356 |
+
|
| 357 |
+
``` cpp
|
| 358 |
+
optional<T>& operator=(nullopt_t) noexcept;
|
| 359 |
+
```
|
| 360 |
+
|
| 361 |
+
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 362 |
+
the contained value; otherwise no effect.
|
| 363 |
+
|
| 364 |
+
*Returns:* `*this`.
|
| 365 |
+
|
| 366 |
+
*Postconditions:* `*this` does not contain a value.
|
| 367 |
+
|
| 368 |
+
``` cpp
|
| 369 |
+
optional<T>& operator=(const optional& rhs);
|
| 370 |
+
```
|
| 371 |
+
|
| 372 |
+
*Effects:* See Table [[tab:optional.assign.copy]].
|
| 373 |
+
|
| 374 |
+
**Table: `optional::operator=(const optional&)` effects** <a id="tab:optional.assign.copy">[tab:optional.assign.copy]</a>
|
| 375 |
+
|
| 376 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 377 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 378 |
+
| `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` |
|
| 379 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
*Returns:* `*this`.
|
| 383 |
+
|
| 384 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 385 |
+
|
| 386 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 387 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 388 |
+
call to `T`’s copy constructor, no effect. If an exception is thrown
|
| 389 |
+
during the call to `T`’s copy assignment, the state of its contained
|
| 390 |
+
value is as defined by the exception safety guarantee of `T`’s copy
|
| 391 |
+
assignment. This operator shall be defined as deleted unless
|
| 392 |
+
`is_copy_constructible_v<T>` is `true` and `is_copy_assignable_v<T>` is
|
| 393 |
+
`true`.
|
| 394 |
+
|
| 395 |
+
``` cpp
|
| 396 |
+
optional<T>& operator=(optional&& rhs) noexcept(see below);
|
| 397 |
+
```
|
| 398 |
+
|
| 399 |
+
*Effects:* See Table [[tab:optional.assign.move]]. The result of the
|
| 400 |
+
expression `bool(rhs)` remains unchanged.
|
| 401 |
+
|
| 402 |
+
**Table: `optional::operator=(optional&&)` effects** <a id="tab:optional.assign.move">[tab:optional.assign.move]</a>
|
| 403 |
+
|
| 404 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 405 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 406 |
+
| `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)` |
|
| 407 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
*Returns:* `*this`.
|
| 411 |
+
|
| 412 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 413 |
+
|
| 414 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 415 |
+
|
| 416 |
+
``` cpp
|
| 417 |
+
is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
If any exception is thrown, the result of the expression `bool(*this)`
|
| 421 |
+
remains unchanged. If an exception is thrown during the call to `T`’s
|
| 422 |
+
move constructor, the state of `*rhs.val` is determined by the exception
|
| 423 |
+
safety guarantee of `T`’s move constructor. If an exception is thrown
|
| 424 |
+
during the call to `T`’s move assignment, the state of `*val` and
|
| 425 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s move
|
| 426 |
+
assignment. This operator shall not participate in overload resolution
|
| 427 |
+
unless `is_move_constructible_v<T>` is `true` and
|
| 428 |
+
`is_move_assignable_v<T>` is `true`.
|
| 429 |
+
|
| 430 |
+
``` cpp
|
| 431 |
+
template <class U = T> optional<T>& operator=(U&& v);
|
| 432 |
+
```
|
| 433 |
+
|
| 434 |
+
*Effects:* If `*this` contains a value, assigns `std::forward<U>(v)` to
|
| 435 |
+
the contained value; otherwise initializes the contained value as if
|
| 436 |
+
direct-non-list-initializing object of type `T` with
|
| 437 |
+
`std::forward<U>(v)`.
|
| 438 |
+
|
| 439 |
+
*Returns:* `*this`.
|
| 440 |
+
|
| 441 |
+
*Postconditions:* `*this` contains a value.
|
| 442 |
+
|
| 443 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 444 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 445 |
+
call to `T`’s constructor, the state of `v` is determined by the
|
| 446 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 447 |
+
thrown during the call to `T`’s assignment, the state of `*val` and `v`
|
| 448 |
+
is determined by the exception safety guarantee of `T`’s assignment.
|
| 449 |
+
This function shall not participate in overload resolution unless
|
| 450 |
+
`is_same_v<optional<T>, decay_t<U>>` is `false`,
|
| 451 |
+
`conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>` is `false`,
|
| 452 |
+
`is_constructible_v<T, U>` is `true`, and `is_assignable_v<T&, U>` is
|
| 453 |
+
`true`.
|
| 454 |
+
|
| 455 |
+
``` cpp
|
| 456 |
+
template <class U> optional<T>& operator=(const optional<U>& rhs);
|
| 457 |
+
```
|
| 458 |
+
|
| 459 |
+
*Effects:* See Table [[tab:optional.assign.copy.templ]].
|
| 460 |
+
|
| 461 |
+
**Table: `optional::operator=(const optional<U>&)` effects** <a id="tab:optional.assign.copy.templ">[tab:optional.assign.copy.templ]</a>
|
| 462 |
+
|
| 463 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 464 |
+
| ------------------------------ | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
| 465 |
+
| `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` |
|
| 466 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
*Returns:* `*this`.
|
| 470 |
+
|
| 471 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 472 |
+
|
| 473 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 474 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 475 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 476 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 477 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 478 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 479 |
+
assignment. This function shall not participate in overload resolution
|
| 480 |
+
unless
|
| 481 |
+
|
| 482 |
+
- `is_constructible_v<T, const U&>` is `true`,
|
| 483 |
+
- `is_assignable_v<T&, const U&>` is `true`,
|
| 484 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 485 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 486 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 487 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 488 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 489 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 490 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`,
|
| 491 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`,
|
| 492 |
+
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 493 |
+
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 494 |
+
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 495 |
+
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 496 |
+
|
| 497 |
+
``` cpp
|
| 498 |
+
template <class U> optional<T>& operator=(optional<U>&& rhs);
|
| 499 |
+
```
|
| 500 |
+
|
| 501 |
+
*Effects:* See Table [[tab:optional.assign.move.templ]]. The result of
|
| 502 |
+
the expression `bool(rhs)` remains unchanged.
|
| 503 |
+
|
| 504 |
+
**Table: `optional::operator=(optional<U>&&)` effects** <a id="tab:optional.assign.move.templ">[tab:optional.assign.move.templ]</a>
|
| 505 |
+
|
| 506 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 507 |
+
| ------------------------------ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 508 |
+
| `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)` |
|
| 509 |
+
| `rhs` does not contain a value | destroys the contained value by calling `val->T::~T()` | no effect |
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
*Returns:* `*this`.
|
| 513 |
+
|
| 514 |
+
*Postconditions:* `bool(rhs) == bool(*this)`.
|
| 515 |
+
|
| 516 |
+
*Remarks:* If any exception is thrown, the result of the expression
|
| 517 |
+
`bool(*this)` remains unchanged. If an exception is thrown during the
|
| 518 |
+
call to `T`’s constructor, the state of `*rhs.val` is determined by the
|
| 519 |
+
exception safety guarantee of `T`’s constructor. If an exception is
|
| 520 |
+
thrown during the call to `T`’s assignment, the state of `*val` and
|
| 521 |
+
`*rhs.val` is determined by the exception safety guarantee of `T`’s
|
| 522 |
+
assignment. This function shall not participate in overload resolution
|
| 523 |
+
unless
|
| 524 |
+
|
| 525 |
+
- `is_constructible_v<T, U>` is `true`,
|
| 526 |
+
- `is_assignable_v<T&, U>` is `true`,
|
| 527 |
+
- `is_constructible_v<T, optional<U>&>` is `false`,
|
| 528 |
+
- `is_constructible_v<T, optional<U>&&>` is `false`,
|
| 529 |
+
- `is_constructible_v<T, const optional<U>&>` is `false`,
|
| 530 |
+
- `is_constructible_v<T, const optional<U>&&>` is `false`,
|
| 531 |
+
- `is_convertible_v<optional<U>&, T>` is `false`,
|
| 532 |
+
- `is_convertible_v<optional<U>&&, T>` is `false`,
|
| 533 |
+
- `is_convertible_v<const optional<U>&, T>` is `false`,
|
| 534 |
+
- `is_convertible_v<const optional<U>&&, T>` is `false`,
|
| 535 |
+
- `is_assignable_v<T&, optional<U>&>` is `false`,
|
| 536 |
+
- `is_assignable_v<T&, optional<U>&&>` is `false`,
|
| 537 |
+
- `is_assignable_v<T&, const optional<U>&>` is `false`, and
|
| 538 |
+
- `is_assignable_v<T&, const optional<U>&&>` is `false`.
|
| 539 |
+
|
| 540 |
+
``` cpp
|
| 541 |
+
template <class... Args> T& emplace(Args&&... args);
|
| 542 |
+
```
|
| 543 |
+
|
| 544 |
+
*Requires:* `is_constructible_v<T, Args&&...>` is `true`.
|
| 545 |
+
|
| 546 |
+
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 547 |
+
as if direct-non-list-initializing an object of type `T` with the
|
| 548 |
+
arguments `std::forward<Args>(args)...`.
|
| 549 |
+
|
| 550 |
+
*Postconditions:* `*this` contains a value.
|
| 551 |
+
|
| 552 |
+
*Returns:* A reference to the new contained value.
|
| 553 |
+
|
| 554 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 555 |
+
|
| 556 |
+
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 557 |
+
constructor, `*this` does not contain a value, and the previous `*val`
|
| 558 |
+
(if any) has been destroyed.
|
| 559 |
+
|
| 560 |
+
``` cpp
|
| 561 |
+
template <class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
|
| 562 |
+
```
|
| 563 |
+
|
| 564 |
+
*Effects:* Calls `*this = nullopt`. Then initializes the contained value
|
| 565 |
+
as if direct-non-list-initializing an object of type `T` with the
|
| 566 |
+
arguments `il, std::forward<Args>(args)...`.
|
| 567 |
+
|
| 568 |
+
*Postconditions:* `*this` contains a value.
|
| 569 |
+
|
| 570 |
+
*Returns:* A reference to the new contained value.
|
| 571 |
+
|
| 572 |
+
*Throws:* Any exception thrown by the selected constructor of `T`.
|
| 573 |
+
|
| 574 |
+
*Remarks:* If an exception is thrown during the call to `T`’s
|
| 575 |
+
constructor, `*this` does not contain a value, and the previous `*val`
|
| 576 |
+
(if any) has been destroyed. This function shall not participate in
|
| 577 |
+
overload resolution unless
|
| 578 |
+
`is_constructible_v<T, initializer_list<U>&, Args&&...>` is `true`.
|
| 579 |
+
|
| 580 |
+
#### Swap <a id="optional.swap">[[optional.swap]]</a>
|
| 581 |
+
|
| 582 |
+
``` cpp
|
| 583 |
+
void swap(optional& rhs) noexcept(see below);
|
| 584 |
+
```
|
| 585 |
+
|
| 586 |
+
*Requires:* Lvalues of type `T` shall be swappable and
|
| 587 |
+
`is_move_constructible_v<T>` is `true`.
|
| 588 |
+
|
| 589 |
+
*Effects:* See Table [[tab:optional.swap]].
|
| 590 |
+
|
| 591 |
+
**Table: `optional::swap(optional&)` effects** <a id="tab:optional.swap">[tab:optional.swap]</a>
|
| 592 |
+
|
| 593 |
+
| | `*this` contains a value | `*this` does not contain a value |
|
| 594 |
+
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 595 |
+
| `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 |
|
| 596 |
+
| `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 |
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
*Throws:* Any exceptions thrown by the operations in the relevant part
|
| 600 |
+
of Table [[tab:optional.swap]].
|
| 601 |
+
|
| 602 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 603 |
+
|
| 604 |
+
``` cpp
|
| 605 |
+
is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>
|
| 606 |
+
```
|
| 607 |
+
|
| 608 |
+
If any exception is thrown, the results of the expressions `bool(*this)`
|
| 609 |
+
and `bool(rhs)` remain unchanged. If an exception is thrown during the
|
| 610 |
+
call to function `swap`, the state of `*val` and `*rhs.val` is
|
| 611 |
+
determined by the exception safety guarantee of `swap` for lvalues of
|
| 612 |
+
`T`. If an exception is thrown during the call to `T`’s move
|
| 613 |
+
constructor, the state of `*val` and `*rhs.val` is determined by the
|
| 614 |
+
exception safety guarantee of `T`’s move constructor.
|
| 615 |
+
|
| 616 |
+
#### Observers <a id="optional.observe">[[optional.observe]]</a>
|
| 617 |
+
|
| 618 |
+
``` cpp
|
| 619 |
+
constexpr const T* operator->() const;
|
| 620 |
+
constexpr T* operator->();
|
| 621 |
+
```
|
| 622 |
+
|
| 623 |
+
*Requires:* `*this` contains a value.
|
| 624 |
+
|
| 625 |
+
*Returns:* `val`.
|
| 626 |
+
|
| 627 |
+
*Throws:* Nothing.
|
| 628 |
+
|
| 629 |
+
*Remarks:* These functions shall be constexpr functions.
|
| 630 |
+
|
| 631 |
+
``` cpp
|
| 632 |
+
constexpr const T& operator*() const&;
|
| 633 |
+
constexpr T& operator*() &;
|
| 634 |
+
```
|
| 635 |
+
|
| 636 |
+
*Requires:* `*this` contains a value.
|
| 637 |
+
|
| 638 |
+
*Returns:* `*val`.
|
| 639 |
+
|
| 640 |
+
*Throws:* Nothing.
|
| 641 |
+
|
| 642 |
+
*Remarks:* These functions shall be constexpr functions.
|
| 643 |
+
|
| 644 |
+
``` cpp
|
| 645 |
+
constexpr T&& operator*() &&;
|
| 646 |
+
constexpr const T&& operator*() const&&;
|
| 647 |
+
```
|
| 648 |
+
|
| 649 |
+
*Requires:* `*this` contains a value.
|
| 650 |
+
|
| 651 |
+
*Effects:* Equivalent to: `return std::move(*val);`
|
| 652 |
+
|
| 653 |
+
``` cpp
|
| 654 |
+
constexpr explicit operator bool() const noexcept;
|
| 655 |
+
```
|
| 656 |
+
|
| 657 |
+
*Returns:* `true` if and only if `*this` contains a value.
|
| 658 |
+
|
| 659 |
+
*Remarks:* This function shall be a constexpr function.
|
| 660 |
+
|
| 661 |
+
``` cpp
|
| 662 |
+
constexpr bool has_value() const noexcept;
|
| 663 |
+
```
|
| 664 |
+
|
| 665 |
+
*Returns:* `true` if and only if `*this` contains a value.
|
| 666 |
+
|
| 667 |
+
*Remarks:* This function shall be a constexpr function.
|
| 668 |
+
|
| 669 |
+
``` cpp
|
| 670 |
+
constexpr const T& value() const&;
|
| 671 |
+
constexpr T& value() &;
|
| 672 |
+
```
|
| 673 |
+
|
| 674 |
+
*Effects:* Equivalent to:
|
| 675 |
+
|
| 676 |
+
``` cpp
|
| 677 |
+
return bool(*this) ? *val : throw bad_optional_access();
|
| 678 |
+
```
|
| 679 |
+
|
| 680 |
+
``` cpp
|
| 681 |
+
constexpr T&& value() &&;
|
| 682 |
+
constexpr const T&& value() const&&;
|
| 683 |
+
```
|
| 684 |
+
|
| 685 |
+
*Effects:* Equivalent to:
|
| 686 |
+
|
| 687 |
+
``` cpp
|
| 688 |
+
return bool(*this) ? std::move(*val) : throw bad_optional_access();
|
| 689 |
+
```
|
| 690 |
+
|
| 691 |
+
``` cpp
|
| 692 |
+
template <class U> constexpr T value_or(U&& v) const&;
|
| 693 |
+
```
|
| 694 |
+
|
| 695 |
+
*Effects:* Equivalent to:
|
| 696 |
+
|
| 697 |
+
``` cpp
|
| 698 |
+
return bool(*this) ? **this : static_cast<T>(std::forward<U>(v));
|
| 699 |
+
```
|
| 700 |
+
|
| 701 |
+
*Remarks:* If `is_copy_constructible_v<T> && is_convertible_v<U&&, T>`
|
| 702 |
+
is `false`, the program is ill-formed.
|
| 703 |
+
|
| 704 |
+
``` cpp
|
| 705 |
+
template <class U> constexpr T value_or(U&& v) &&;
|
| 706 |
+
```
|
| 707 |
+
|
| 708 |
+
*Effects:* Equivalent to:
|
| 709 |
+
|
| 710 |
+
``` cpp
|
| 711 |
+
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|
| 712 |
+
```
|
| 713 |
+
|
| 714 |
+
*Remarks:* If `is_move_constructible_v<T> && is_convertible_v<U&&, T>`
|
| 715 |
+
is `false`, the program is ill-formed.
|
| 716 |
+
|
| 717 |
+
#### Modifiers <a id="optional.mod">[[optional.mod]]</a>
|
| 718 |
+
|
| 719 |
+
``` cpp
|
| 720 |
+
void reset() noexcept;
|
| 721 |
+
```
|
| 722 |
+
|
| 723 |
+
*Effects:* If `*this` contains a value, calls `val->T::T̃()` to destroy
|
| 724 |
+
the contained value; otherwise no effect.
|
| 725 |
+
|
| 726 |
+
*Postconditions:* `*this` does not contain a value.
|
| 727 |
+
|
| 728 |
+
### No-value state indicator <a id="optional.nullopt">[[optional.nullopt]]</a>
|
| 729 |
+
|
| 730 |
+
``` cpp
|
| 731 |
+
struct nullopt_t{see below};
|
| 732 |
+
inline constexpr nullopt_t nullopt(unspecified);
|
| 733 |
+
```
|
| 734 |
+
|
| 735 |
+
The struct `nullopt_t` is an empty structure type used as a unique type
|
| 736 |
+
to indicate the state of not containing a value for `optional` objects.
|
| 737 |
+
In particular, `optional<T>` has a constructor with `nullopt_t` as a
|
| 738 |
+
single argument; this indicates that an optional object not containing a
|
| 739 |
+
value shall be constructed.
|
| 740 |
+
|
| 741 |
+
Type `nullopt_t` shall not have a default constructor or an
|
| 742 |
+
initializer-list constructor, and shall not be an aggregate.
|
| 743 |
+
|
| 744 |
+
### Class `bad_optional_access` <a id="optional.bad.access">[[optional.bad.access]]</a>
|
| 745 |
+
|
| 746 |
+
``` cpp
|
| 747 |
+
class bad_optional_access : public exception {
|
| 748 |
+
public:
|
| 749 |
+
bad_optional_access();
|
| 750 |
+
};
|
| 751 |
+
```
|
| 752 |
+
|
| 753 |
+
The class `bad_optional_access` defines the type of objects thrown as
|
| 754 |
+
exceptions to report the situation where an attempt is made to access
|
| 755 |
+
the value of an optional object that does not contain a value.
|
| 756 |
+
|
| 757 |
+
``` cpp
|
| 758 |
+
bad_optional_access();
|
| 759 |
+
```
|
| 760 |
+
|
| 761 |
+
*Effects:* Constructs an object of class `bad_optional_access`.
|
| 762 |
+
|
| 763 |
+
*Postconditions:* `what()` returns an *implementation-defined* NTBS.
|
| 764 |
+
|
| 765 |
+
### Relational operators <a id="optional.relops">[[optional.relops]]</a>
|
| 766 |
+
|
| 767 |
+
``` cpp
|
| 768 |
+
template <class T, class U> constexpr bool operator==(const optional<T>& x, const optional<U>& y);
|
| 769 |
+
```
|
| 770 |
+
|
| 771 |
+
*Requires:* The expression `*x == *y` shall be well-formed and its
|
| 772 |
+
result shall be convertible to `bool`.
|
| 773 |
+
|
| 774 |
+
[*Note 1*: `T` need not be `EqualityComparable`. — *end note*]
|
| 775 |
+
|
| 776 |
+
*Returns:* If `bool(x) != bool(y)`, `false`; otherwise if
|
| 777 |
+
`bool(x) == false`, `true`; otherwise `*x == *y`.
|
| 778 |
+
|
| 779 |
+
*Remarks:* Specializations of this function template for which
|
| 780 |
+
`*x == *y` is a core constant expression shall be constexpr functions.
|
| 781 |
+
|
| 782 |
+
``` cpp
|
| 783 |
+
template <class T, class U> constexpr bool operator!=(const optional<T>& x, const optional<U>& y);
|
| 784 |
+
```
|
| 785 |
+
|
| 786 |
+
*Requires:* The expression `*x != *y` shall be well-formed and its
|
| 787 |
+
result shall be convertible to `bool`.
|
| 788 |
+
|
| 789 |
+
*Returns:* If `bool(x) != bool(y)`, `true`; otherwise, if
|
| 790 |
+
`bool(x) == false`, `false`; otherwise `*x != *y`.
|
| 791 |
+
|
| 792 |
+
*Remarks:* Specializations of this function template for which
|
| 793 |
+
`*x != *y` is a core constant expression shall be constexpr functions.
|
| 794 |
+
|
| 795 |
+
``` cpp
|
| 796 |
+
template <class T, class U> constexpr bool operator<(const optional<T>& x, const optional<U>& y);
|
| 797 |
+
```
|
| 798 |
+
|
| 799 |
+
*Requires:* `*x < *y` shall be well-formed and its result shall be
|
| 800 |
+
convertible to `bool`.
|
| 801 |
+
|
| 802 |
+
*Returns:* If `!y`, `false`; otherwise, if `!x`, `true`; otherwise
|
| 803 |
+
`*x < *y`.
|
| 804 |
+
|
| 805 |
+
*Remarks:* Specializations of this function template for which `*x < *y`
|
| 806 |
+
is a core constant expression shall be constexpr functions.
|
| 807 |
+
|
| 808 |
+
``` cpp
|
| 809 |
+
template <class T, class U> constexpr bool operator>(const optional<T>& x, const optional<U>& y);
|
| 810 |
+
```
|
| 811 |
+
|
| 812 |
+
*Requires:* The expression `*x > *y` shall be well-formed and its result
|
| 813 |
+
shall be convertible to `bool`.
|
| 814 |
+
|
| 815 |
+
*Returns:* If `!x`, `false`; otherwise, if `!y`, `true`; otherwise
|
| 816 |
+
`*x > *y`.
|
| 817 |
+
|
| 818 |
+
*Remarks:* Specializations of this function template for which `*x > *y`
|
| 819 |
+
is a core constant expression shall be constexpr functions.
|
| 820 |
+
|
| 821 |
+
``` cpp
|
| 822 |
+
template <class T, class U> constexpr bool operator<=(const optional<T>& x, const optional<U>& y);
|
| 823 |
+
```
|
| 824 |
+
|
| 825 |
+
*Requires:* The expression `*x <= *y` shall be well-formed and its
|
| 826 |
+
result shall be convertible to `bool`.
|
| 827 |
+
|
| 828 |
+
*Returns:* If `!x`, `true`; otherwise, if `!y`, `false`; otherwise
|
| 829 |
+
`*x <= *y`.
|
| 830 |
+
|
| 831 |
+
*Remarks:* Specializations of this function template for which
|
| 832 |
+
`*x <= *y` is a core constant expression shall be constexpr functions.
|
| 833 |
+
|
| 834 |
+
``` cpp
|
| 835 |
+
template <class T, class U> constexpr bool operator>=(const optional<T>& x, const optional<U>& y);
|
| 836 |
+
```
|
| 837 |
+
|
| 838 |
+
*Requires:* The expression `*x >= *y` shall be well-formed and its
|
| 839 |
+
result shall be convertible to `bool`.
|
| 840 |
+
|
| 841 |
+
*Returns:* If `!y`, `true`; otherwise, if `!x`, `false`; otherwise
|
| 842 |
+
`*x >= *y`.
|
| 843 |
+
|
| 844 |
+
*Remarks:* Specializations of this function template for which
|
| 845 |
+
`*x >= *y` is a core constant expression shall be constexpr functions.
|
| 846 |
+
|
| 847 |
+
### Comparison with `nullopt` <a id="optional.nullops">[[optional.nullops]]</a>
|
| 848 |
+
|
| 849 |
+
``` cpp
|
| 850 |
+
template <class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept;
|
| 851 |
+
template <class T> constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept;
|
| 852 |
+
```
|
| 853 |
+
|
| 854 |
+
*Returns:* `!x`.
|
| 855 |
+
|
| 856 |
+
``` cpp
|
| 857 |
+
template <class T> constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept;
|
| 858 |
+
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept;
|
| 859 |
+
```
|
| 860 |
+
|
| 861 |
+
*Returns:* `bool(x)`.
|
| 862 |
+
|
| 863 |
+
``` cpp
|
| 864 |
+
template <class T> constexpr bool operator<(const optional<T>& x, nullopt_t) noexcept;
|
| 865 |
+
```
|
| 866 |
+
|
| 867 |
+
*Returns:* `false`.
|
| 868 |
+
|
| 869 |
+
``` cpp
|
| 870 |
+
template <class T> constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept;
|
| 871 |
+
```
|
| 872 |
+
|
| 873 |
+
*Returns:* `bool(x)`.
|
| 874 |
+
|
| 875 |
+
``` cpp
|
| 876 |
+
template <class T> constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept;
|
| 877 |
+
```
|
| 878 |
+
|
| 879 |
+
*Returns:* `!x`.
|
| 880 |
+
|
| 881 |
+
``` cpp
|
| 882 |
+
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>& x) noexcept;
|
| 883 |
+
```
|
| 884 |
+
|
| 885 |
+
*Returns:* `true`.
|
| 886 |
+
|
| 887 |
+
``` cpp
|
| 888 |
+
template <class T> constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept;
|
| 889 |
+
```
|
| 890 |
+
|
| 891 |
+
*Returns:* `bool(x)`.
|
| 892 |
+
|
| 893 |
+
``` cpp
|
| 894 |
+
template <class T> constexpr bool operator>(nullopt_t, const optional<T>& x) noexcept;
|
| 895 |
+
```
|
| 896 |
+
|
| 897 |
+
*Returns:* `false`.
|
| 898 |
+
|
| 899 |
+
``` cpp
|
| 900 |
+
template <class T> constexpr bool operator>=(const optional<T>& x, nullopt_t) noexcept;
|
| 901 |
+
```
|
| 902 |
+
|
| 903 |
+
*Returns:* `true`.
|
| 904 |
+
|
| 905 |
+
``` cpp
|
| 906 |
+
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept;
|
| 907 |
+
```
|
| 908 |
+
|
| 909 |
+
*Returns:* `!x`.
|
| 910 |
+
|
| 911 |
+
### Comparison with `T` <a id="optional.comp_with_t">[[optional.comp_with_t]]</a>
|
| 912 |
+
|
| 913 |
+
``` cpp
|
| 914 |
+
template <class T, class U> constexpr bool operator==(const optional<T>& x, const U& v);
|
| 915 |
+
```
|
| 916 |
+
|
| 917 |
+
*Requires:* The expression `*x == v` shall be well-formed and its result
|
| 918 |
+
shall be convertible to `bool`.
|
| 919 |
+
|
| 920 |
+
[*Note 1*: `T` need not be `EqualityComparable`. — *end note*]
|
| 921 |
+
|
| 922 |
+
*Effects:* Equivalent to: `return bool(x) ? *x == v : false;`
|
| 923 |
+
|
| 924 |
+
``` cpp
|
| 925 |
+
template <class T, class U> constexpr bool operator==(const U& v, const optional<T>& x);
|
| 926 |
+
```
|
| 927 |
+
|
| 928 |
+
*Requires:* The expression `v == *x` shall be well-formed and its result
|
| 929 |
+
shall be convertible to `bool`.
|
| 930 |
+
|
| 931 |
+
*Effects:* Equivalent to: `return bool(x) ? v == *x : false;`
|
| 932 |
+
|
| 933 |
+
``` cpp
|
| 934 |
+
template <class T, class U> constexpr bool operator!=(const optional<T>& x, const U& v);
|
| 935 |
+
```
|
| 936 |
+
|
| 937 |
+
*Requires:* The expression `*x != v` shall be well-formed and its result
|
| 938 |
+
shall be convertible to `bool`.
|
| 939 |
+
|
| 940 |
+
*Effects:* Equivalent to: `return bool(x) ? *x != v : true;`
|
| 941 |
+
|
| 942 |
+
``` cpp
|
| 943 |
+
template <class T, class U> constexpr bool operator!=(const U& v, const optional<T>& x);
|
| 944 |
+
```
|
| 945 |
+
|
| 946 |
+
*Requires:* The expression `v != *x` shall be well-formed and its result
|
| 947 |
+
shall be convertible to `bool`.
|
| 948 |
+
|
| 949 |
+
*Effects:* Equivalent to: `return bool(x) ? v != *x : true;`
|
| 950 |
+
|
| 951 |
+
``` cpp
|
| 952 |
+
template <class T, class U> constexpr bool operator<(const optional<T>& x, const U& v);
|
| 953 |
+
```
|
| 954 |
+
|
| 955 |
+
*Requires:* The expression `*x < v` shall be well-formed and its result
|
| 956 |
+
shall be convertible to `bool`.
|
| 957 |
+
|
| 958 |
+
*Effects:* Equivalent to: `return bool(x) ? *x < v : true;`
|
| 959 |
+
|
| 960 |
+
``` cpp
|
| 961 |
+
template <class T, class U> constexpr bool operator<(const U& v, const optional<T>& x);
|
| 962 |
+
```
|
| 963 |
+
|
| 964 |
+
*Requires:* The expression `v < *x` shall be well-formed and its result
|
| 965 |
+
shall be convertible to `bool`.
|
| 966 |
+
|
| 967 |
+
*Effects:* Equivalent to: `return bool(x) ? v < *x : false;`
|
| 968 |
+
|
| 969 |
+
``` cpp
|
| 970 |
+
template <class T, class U> constexpr bool operator<=(const optional<T>& x, const U& v);
|
| 971 |
+
```
|
| 972 |
+
|
| 973 |
+
*Requires:* The expression `*x <= v` shall be well-formed and its result
|
| 974 |
+
shall be convertible to `bool`.
|
| 975 |
+
|
| 976 |
+
*Effects:* Equivalent to: `return bool(x) ? *x <= v : true;`
|
| 977 |
+
|
| 978 |
+
``` cpp
|
| 979 |
+
template <class T, class U> constexpr bool operator<=(const U& v, const optional<T>& x);
|
| 980 |
+
```
|
| 981 |
+
|
| 982 |
+
*Requires:* The expression `v <= *x` shall be well-formed and its result
|
| 983 |
+
shall be convertible to `bool`.
|
| 984 |
+
|
| 985 |
+
*Effects:* Equivalent to: `return bool(x) ? v <= *x : false;`
|
| 986 |
+
|
| 987 |
+
``` cpp
|
| 988 |
+
template <class T, class U> constexpr bool operator>(const optional<T>& x, const U& v);
|
| 989 |
+
```
|
| 990 |
+
|
| 991 |
+
*Requires:* The expression `*x > v` shall be well-formed and its result
|
| 992 |
+
shall be convertible to `bool`.
|
| 993 |
+
|
| 994 |
+
*Effects:* Equivalent to: `return bool(x) ? *x > v : false;`
|
| 995 |
+
|
| 996 |
+
``` cpp
|
| 997 |
+
template <class T, class U> constexpr bool operator>(const U& v, const optional<T>& x);
|
| 998 |
+
```
|
| 999 |
+
|
| 1000 |
+
*Requires:* The expression `v > *x` shall be well-formed and its result
|
| 1001 |
+
shall be convertible to `bool`.
|
| 1002 |
+
|
| 1003 |
+
*Effects:* Equivalent to: `return bool(x) ? v > *x : true;`
|
| 1004 |
+
|
| 1005 |
+
``` cpp
|
| 1006 |
+
template <class T, class U> constexpr bool operator>=(const optional<T>& x, const U& v);
|
| 1007 |
+
```
|
| 1008 |
+
|
| 1009 |
+
*Requires:* The expression `*x >= v` shall be well-formed and its result
|
| 1010 |
+
shall be convertible to `bool`.
|
| 1011 |
+
|
| 1012 |
+
*Effects:* Equivalent to: `return bool(x) ? *x >= v : false;`
|
| 1013 |
+
|
| 1014 |
+
``` cpp
|
| 1015 |
+
template <class T, class U> constexpr bool operator>=(const U& v, const optional<T>& x);
|
| 1016 |
+
```
|
| 1017 |
+
|
| 1018 |
+
*Requires:* The expression `v >= *x` shall be well-formed and its result
|
| 1019 |
+
shall be convertible to `bool`.
|
| 1020 |
+
|
| 1021 |
+
*Effects:* Equivalent to: `return bool(x) ? v >= *x : true;`
|
| 1022 |
+
|
| 1023 |
+
### Specialized algorithms <a id="optional.specalg">[[optional.specalg]]</a>
|
| 1024 |
+
|
| 1025 |
+
``` cpp
|
| 1026 |
+
template <class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
|
| 1027 |
+
```
|
| 1028 |
+
|
| 1029 |
+
*Effects:* Calls `x.swap(y)`.
|
| 1030 |
+
|
| 1031 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 1032 |
+
unless `is_move_constructible_v<T>` is `true` and `is_swappable_v<T>` is
|
| 1033 |
+
`true`.
|
| 1034 |
+
|
| 1035 |
+
``` cpp
|
| 1036 |
+
template <class T> constexpr optional<decay_t<T>> make_optional(T&& v);
|
| 1037 |
+
```
|
| 1038 |
+
|
| 1039 |
+
*Returns:* `optional<decay_t<T>>(std::forward<T>(v))`.
|
| 1040 |
+
|
| 1041 |
+
``` cpp
|
| 1042 |
+
template <class T, class...Args>
|
| 1043 |
+
constexpr optional<T> make_optional(Args&&... args);
|
| 1044 |
+
```
|
| 1045 |
+
|
| 1046 |
+
*Effects:* Equivalent to:
|
| 1047 |
+
`return optional<T>(in_place, std::forward<Args>(args)...);`
|
| 1048 |
+
|
| 1049 |
+
``` cpp
|
| 1050 |
+
template <class T, class U, class... Args>
|
| 1051 |
+
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
|
| 1052 |
+
```
|
| 1053 |
+
|
| 1054 |
+
*Effects:* Equivalent to:
|
| 1055 |
+
`return optional<T>(in_place, il, std::forward<Args>(args)...);`
|
| 1056 |
+
|
| 1057 |
+
### Hash support <a id="optional.hash">[[optional.hash]]</a>
|
| 1058 |
+
|
| 1059 |
+
``` cpp
|
| 1060 |
+
template <class T> struct hash<optional<T>>;
|
| 1061 |
+
```
|
| 1062 |
+
|
| 1063 |
+
The specialization `hash<optional<T>>` is enabled ([[unord.hash]]) if
|
| 1064 |
+
and only if `hash<remove_const_t<T>>` is enabled. When enabled, for an
|
| 1065 |
+
object `o` of type `optional<T>`, if `bool(o) == true`, then
|
| 1066 |
+
`hash<optional<T>>()(o)` shall evaluate to the same value as
|
| 1067 |
+
`hash<remove_const_t<T>>()(*o)`; otherwise it evaluates to an
|
| 1068 |
+
unspecified value. The member functions are not guaranteed to be
|
| 1069 |
+
`noexcept`.
|
| 1070 |
+
|