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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Partial specialization of `optional` for reference types <a id="optional.optional.ref">[[optional.optional.ref]]</a>
|
| 2 |
+
|
| 3 |
+
#### General <a id="optional.optional.ref.general">[[optional.optional.ref.general]]</a>
|
| 4 |
+
|
| 5 |
+
``` cpp
|
| 6 |
+
namespace std {
|
| 7 |
+
template<class T>
|
| 8 |
+
class optional<T&> {
|
| 9 |
+
public:
|
| 10 |
+
using value_type = T;
|
| 11 |
+
using iterator = implementation-defined; // see~[optional.ref.iterators]
|
| 12 |
+
|
| 13 |
+
public:
|
| 14 |
+
// [optional.ref.ctor], constructors
|
| 15 |
+
constexpr optional() noexcept = default;
|
| 16 |
+
constexpr optional(nullopt_t) noexcept : optional() {}
|
| 17 |
+
constexpr optional(const optional& rhs) noexcept = default;
|
| 18 |
+
|
| 19 |
+
template<class Arg>
|
| 20 |
+
constexpr explicit optional(in_place_t, Arg&& arg);
|
| 21 |
+
template<class U>
|
| 22 |
+
constexpr explicit(see below) optional(U&& u) noexcept(see below);
|
| 23 |
+
template<class U>
|
| 24 |
+
constexpr explicit(see below) optional(optional<U>& rhs) noexcept(see below);
|
| 25 |
+
template<class U>
|
| 26 |
+
constexpr explicit(see below) optional(const optional<U>& rhs) noexcept(see below);
|
| 27 |
+
template<class U>
|
| 28 |
+
constexpr explicit(see below) optional(optional<U>&& rhs) noexcept(see below);
|
| 29 |
+
template<class U>
|
| 30 |
+
constexpr explicit(see below) optional(const optional<U>&& rhs) noexcept(see below);
|
| 31 |
+
|
| 32 |
+
constexpr ~optional() = default;
|
| 33 |
+
|
| 34 |
+
// [optional.ref.assign], assignment
|
| 35 |
+
constexpr optional& operator=(nullopt_t) noexcept;
|
| 36 |
+
constexpr optional& operator=(const optional& rhs) noexcept = default;
|
| 37 |
+
|
| 38 |
+
template<class U> constexpr T& emplace(U&& u) noexcept(see below);
|
| 39 |
+
|
| 40 |
+
// [optional.ref.swap], swap
|
| 41 |
+
constexpr void swap(optional& rhs) noexcept;
|
| 42 |
+
|
| 43 |
+
// [optional.ref.iterators], iterator support
|
| 44 |
+
constexpr iterator begin() const noexcept;
|
| 45 |
+
constexpr iterator end() const noexcept;
|
| 46 |
+
|
| 47 |
+
// [optional.ref.observe], observers
|
| 48 |
+
constexpr T* operator->() const noexcept;
|
| 49 |
+
constexpr T& operator*() const noexcept;
|
| 50 |
+
constexpr explicit operator bool() const noexcept;
|
| 51 |
+
constexpr bool has_value() const noexcept;
|
| 52 |
+
constexpr T& value() const; // freestanding-deleted
|
| 53 |
+
template<class U = remove_cv_t<T>>
|
| 54 |
+
constexpr remove_cv_t<T> value_or(U&& u) const;
|
| 55 |
+
|
| 56 |
+
// [optional.ref.monadic], monadic operations
|
| 57 |
+
template<class F> constexpr auto and_then(F&& f) const;
|
| 58 |
+
template<class F> constexpr optional<invoke_result_t<F, T&>> transform(F&& f) const;
|
| 59 |
+
template<class F> constexpr optional or_else(F&& f) const;
|
| 60 |
+
|
| 61 |
+
// [optional.ref.mod], modifiers
|
| 62 |
+
constexpr void reset() noexcept;
|
| 63 |
+
|
| 64 |
+
private:
|
| 65 |
+
T* val = nullptr; // exposition only
|
| 66 |
+
|
| 67 |
+
// [optional.ref.expos], exposition only helper functions
|
| 68 |
+
template<class U>
|
| 69 |
+
constexpr void convert-ref-init-val(U&& u); // exposition only
|
| 70 |
+
};
|
| 71 |
+
}
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
An object of type `optional<T&>` *contains a value* if and only if
|
| 75 |
+
`val != nullptr` is `true`. When an `optional<T&>` contains a value, the
|
| 76 |
+
*contained value* is a reference to `*val`.
|
| 77 |
+
|
| 78 |
+
#### Constructors <a id="optional.ref.ctor">[[optional.ref.ctor]]</a>
|
| 79 |
+
|
| 80 |
+
``` cpp
|
| 81 |
+
template<class Arg>
|
| 82 |
+
constexpr explicit optional(in_place_t, Arg&& arg);
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
*Constraints:*
|
| 86 |
+
|
| 87 |
+
- `is_constructible_v<T&, Arg>` is `true`, and
|
| 88 |
+
- `reference_constructs_from_temporary_v<T&, Arg>` is `false`.
|
| 89 |
+
|
| 90 |
+
*Effects:* Equivalent to:
|
| 91 |
+
*`convert-ref-init-val`*`(std::forward<Arg>(arg))`.
|
| 92 |
+
|
| 93 |
+
*Ensures:* `*this` contains a value.
|
| 94 |
+
|
| 95 |
+
``` cpp
|
| 96 |
+
template<class U>
|
| 97 |
+
constexpr explicit(!is_convertible_v<U, T&>)
|
| 98 |
+
optional(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
*Constraints:*
|
| 102 |
+
|
| 103 |
+
- `is_same_v<remove_cvref_t<U>, optional>` is `false`,
|
| 104 |
+
- `is_same_v<remove_cvref_t<U>, in_place_t>` is `false`, and
|
| 105 |
+
- `is_constructible_v<T&, U>` is `true`.
|
| 106 |
+
|
| 107 |
+
*Effects:* Equivalent to:
|
| 108 |
+
*`convert-ref-init-val`*`(std::forward<U>(u))`.
|
| 109 |
+
|
| 110 |
+
*Ensures:* `*this` contains a value.
|
| 111 |
+
|
| 112 |
+
*Remarks:* This constructor is defined as deleted if
|
| 113 |
+
|
| 114 |
+
``` cpp
|
| 115 |
+
reference_constructs_from_temporary_v<T&, U>
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
is `true`.
|
| 119 |
+
|
| 120 |
+
``` cpp
|
| 121 |
+
template<class U>
|
| 122 |
+
constexpr explicit(!is_convertible_v<U&, T&>)
|
| 123 |
+
optional(optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, U&>);
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
*Constraints:*
|
| 127 |
+
|
| 128 |
+
- `is_same_v<remove_cv_t<T>, optional<U>>` is `false`,
|
| 129 |
+
- `is_same_v<T&, U>` is `false`, and
|
| 130 |
+
- `is_constructible_v<T&, U&>` is `true`.
|
| 131 |
+
|
| 132 |
+
*Effects:* Equivalent to:
|
| 133 |
+
|
| 134 |
+
``` cpp
|
| 135 |
+
if (rhs.has_value()) convert-ref-init-val(*rhs);
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
*Remarks:* This constructor is defined as deleted if
|
| 139 |
+
|
| 140 |
+
``` cpp
|
| 141 |
+
reference_constructs_from_temporary_v<T&, U&>
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
is `true`.
|
| 145 |
+
|
| 146 |
+
``` cpp
|
| 147 |
+
template<class U>
|
| 148 |
+
constexpr explicit(!is_convertible_v<const U&, T&>)
|
| 149 |
+
optional(const optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, const U&>);
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
*Constraints:*
|
| 153 |
+
|
| 154 |
+
- `is_same_v<remove_cv_t<T>, optional<U>>` is `false`,
|
| 155 |
+
- `is_same_v<T&, U>` is `false`, and
|
| 156 |
+
- `is_constructible_v<T&, const U&>` is `true`.
|
| 157 |
+
|
| 158 |
+
*Effects:* Equivalent to:
|
| 159 |
+
|
| 160 |
+
``` cpp
|
| 161 |
+
if (rhs.has_value()) convert-ref-init-val(*rhs);
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
*Remarks:* This constructor is defined as deleted if
|
| 165 |
+
|
| 166 |
+
``` cpp
|
| 167 |
+
reference_constructs_from_temporary_v<T&, const U&>
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
is `true`.
|
| 171 |
+
|
| 172 |
+
``` cpp
|
| 173 |
+
template<class U>
|
| 174 |
+
constexpr explicit(!is_convertible_v<U, T&>)
|
| 175 |
+
optional(optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, U>);
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
*Constraints:*
|
| 179 |
+
|
| 180 |
+
- `is_same_v<remove_cv_t<T>, optional<U>>` is `false`,
|
| 181 |
+
- `is_same_v<T&, U>` is `false`, and
|
| 182 |
+
- `is_constructible_v<T&, U>` is `true`.
|
| 183 |
+
|
| 184 |
+
*Effects:* Equivalent to:
|
| 185 |
+
|
| 186 |
+
``` cpp
|
| 187 |
+
if (rhs.has_value()) convert-ref-init-val(*std::move(rhs));
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
*Remarks:* This constructor is defined as deleted if
|
| 191 |
+
|
| 192 |
+
``` cpp
|
| 193 |
+
reference_constructs_from_temporary_v<T&, U>
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
is `true`.
|
| 197 |
+
|
| 198 |
+
``` cpp
|
| 199 |
+
template<class U>
|
| 200 |
+
constexpr explicit(!is_convertible_v<const U, T&>)
|
| 201 |
+
optional(const optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, const U>);
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
*Constraints:*
|
| 205 |
+
|
| 206 |
+
- `is_same_v<remove_cv_t<T>, optional<U>>` is `false`,
|
| 207 |
+
- `is_same_v<T&, U>` is `false`, and
|
| 208 |
+
- `is_constructible_v<T&, const U>` is `true`.
|
| 209 |
+
|
| 210 |
+
*Effects:* Equivalent to:
|
| 211 |
+
|
| 212 |
+
``` cpp
|
| 213 |
+
if (rhs.has_value()) convert-ref-init-val(*std::move(rhs));
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
*Remarks:* This constructor is defined as deleted if
|
| 217 |
+
|
| 218 |
+
``` cpp
|
| 219 |
+
reference_constructs_from_temporary_v<T&, const U>
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
is `true`.
|
| 223 |
+
|
| 224 |
+
#### Assignment <a id="optional.ref.assign">[[optional.ref.assign]]</a>
|
| 225 |
+
|
| 226 |
+
``` cpp
|
| 227 |
+
constexpr optional& operator=(nullopt_t) noexcept;
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
*Effects:* Assigns `nullptr` to *val*.
|
| 231 |
+
|
| 232 |
+
*Ensures:* `*this` does not contain a value.
|
| 233 |
+
|
| 234 |
+
*Returns:* `*this`.
|
| 235 |
+
|
| 236 |
+
``` cpp
|
| 237 |
+
template<class U>
|
| 238 |
+
constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
*Constraints:*
|
| 242 |
+
|
| 243 |
+
- `is_constructible_v<T&, U>` is `true`, and
|
| 244 |
+
- `reference_constructs_from_temporary_v<T&, U>` is `false`.
|
| 245 |
+
|
| 246 |
+
*Effects:* Equivalent to:
|
| 247 |
+
*`convert-ref-init-val`*`(std::forward<U>(u))`.
|
| 248 |
+
|
| 249 |
+
*Returns:* `*`*`val`*.
|
| 250 |
+
|
| 251 |
+
#### Swap <a id="optional.ref.swap">[[optional.ref.swap]]</a>
|
| 252 |
+
|
| 253 |
+
``` cpp
|
| 254 |
+
constexpr void swap(optional& rhs) noexcept;
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
*Effects:* Equivalent to: `swap(`*`val`*`, rhs.`*`val`*`)`.
|
| 258 |
+
|
| 259 |
+
#### Iterator support <a id="optional.ref.iterators">[[optional.ref.iterators]]</a>
|
| 260 |
+
|
| 261 |
+
``` cpp
|
| 262 |
+
using iterator = implementation-defined;
|
| 263 |
+
```
|
| 264 |
+
|
| 265 |
+
This type models `contiguous_iterator` [[iterator.concept.contiguous]],
|
| 266 |
+
meets the *Cpp17RandomAccessIterator*
|
| 267 |
+
requirements [[random.access.iterators]], and meets the requirements for
|
| 268 |
+
constexpr iterators [[iterator.requirements.general]], with value type
|
| 269 |
+
`remove_cv_t<T>`. The reference type is `T&` for `iterator`.
|
| 270 |
+
|
| 271 |
+
All requirements on container iterators [[container.reqmts]] apply to
|
| 272 |
+
`optional::iterator`.
|
| 273 |
+
|
| 274 |
+
``` cpp
|
| 275 |
+
constexpr iterator begin() const noexcept;
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
*Returns:* If `has_value()` is `true`, an iterator referring to
|
| 279 |
+
`*`*`val`*. Otherwise, a past-the-end iterator value.
|
| 280 |
+
|
| 281 |
+
``` cpp
|
| 282 |
+
constexpr iterator end() const noexcept;
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
*Returns:* `begin() + has_value()`.
|
| 286 |
+
|
| 287 |
+
#### Observers <a id="optional.ref.observe">[[optional.ref.observe]]</a>
|
| 288 |
+
|
| 289 |
+
``` cpp
|
| 290 |
+
constexpr T* operator->() const noexcept;
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
`has_value()` is `true`.
|
| 294 |
+
|
| 295 |
+
*Returns:* *val*.
|
| 296 |
+
|
| 297 |
+
``` cpp
|
| 298 |
+
constexpr T& operator*() const noexcept;
|
| 299 |
+
```
|
| 300 |
+
|
| 301 |
+
`has_value()` is `true`.
|
| 302 |
+
|
| 303 |
+
*Returns:* `*`*`val`*.
|
| 304 |
+
|
| 305 |
+
``` cpp
|
| 306 |
+
constexpr explicit operator bool() const noexcept;
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
*Returns:* *`val`*` != nullptr`.
|
| 310 |
+
|
| 311 |
+
``` cpp
|
| 312 |
+
constexpr bool has_value() const noexcept;
|
| 313 |
+
```
|
| 314 |
+
|
| 315 |
+
*Returns:* *`val`*` != nullptr`.
|
| 316 |
+
|
| 317 |
+
``` cpp
|
| 318 |
+
constexpr T& value() const;
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
*Effects:* Equivalent to:
|
| 322 |
+
|
| 323 |
+
``` cpp
|
| 324 |
+
return has_value() ? *val : throw bad_optional_access();
|
| 325 |
+
```
|
| 326 |
+
|
| 327 |
+
``` cpp
|
| 328 |
+
template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const;
|
| 329 |
+
```
|
| 330 |
+
|
| 331 |
+
Let `X` be `remove_cv_t<T>`.
|
| 332 |
+
|
| 333 |
+
*Mandates:* `is_constructible_v<X, T&> && is_convertible_v<U, X>` is
|
| 334 |
+
`true`.
|
| 335 |
+
|
| 336 |
+
*Effects:* Equivalent to:
|
| 337 |
+
|
| 338 |
+
``` cpp
|
| 339 |
+
return has_value() ? *val : static_cast<X>(std::forward<U>(u));
|
| 340 |
+
```
|
| 341 |
+
|
| 342 |
+
#### Monadic operations <a id="optional.ref.monadic">[[optional.ref.monadic]]</a>
|
| 343 |
+
|
| 344 |
+
``` cpp
|
| 345 |
+
template<class F> constexpr auto and_then(F&& f) const;
|
| 346 |
+
```
|
| 347 |
+
|
| 348 |
+
Let `U` be `invoke_result_t<F, T&>`.
|
| 349 |
+
|
| 350 |
+
*Mandates:* `remove_cvref_t<U>` is a specialization of `optional`.
|
| 351 |
+
|
| 352 |
+
*Effects:* Equivalent to:
|
| 353 |
+
|
| 354 |
+
``` cpp
|
| 355 |
+
if (has_value()) {
|
| 356 |
+
return invoke(std::forward<F>(f), *val);
|
| 357 |
+
} else {
|
| 358 |
+
return remove_cvref_t<U>();
|
| 359 |
+
}
|
| 360 |
+
```
|
| 361 |
+
|
| 362 |
+
``` cpp
|
| 363 |
+
template<class F>
|
| 364 |
+
constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
|
| 365 |
+
```
|
| 366 |
+
|
| 367 |
+
Let `U` be `remove_cv_t<invoke_result_t<F, T&>>`.
|
| 368 |
+
|
| 369 |
+
*Mandates:* The declaration
|
| 370 |
+
|
| 371 |
+
``` cpp
|
| 372 |
+
U u(invoke(std::forward<F>(f), *val));
|
| 373 |
+
```
|
| 374 |
+
|
| 375 |
+
is well-formed for some invented variable `u`.
|
| 376 |
+
|
| 377 |
+
[*Note 1*: There is no requirement that `U` is
|
| 378 |
+
movable [[dcl.init.general]]. — *end note*]
|
| 379 |
+
|
| 380 |
+
*Returns:* If `*this` contains a value, an `optional<U>` object whose
|
| 381 |
+
contained value is direct-non-list-initialized with
|
| 382 |
+
`invoke(std::forward<F>(f), *`*`val`*`)`; otherwise, `optional<U>()`.
|
| 383 |
+
|
| 384 |
+
``` cpp
|
| 385 |
+
template<class F> constexpr optional or_else(F&& f) const;
|
| 386 |
+
```
|
| 387 |
+
|
| 388 |
+
*Constraints:* `F` models `invocable`.
|
| 389 |
+
|
| 390 |
+
*Mandates:* `is_same_v<remove_cvref_t<invoke_result_t<F>>, optional>` is
|
| 391 |
+
`true`.
|
| 392 |
+
|
| 393 |
+
*Effects:* Equivalent to:
|
| 394 |
+
|
| 395 |
+
``` cpp
|
| 396 |
+
if (has_value()) {
|
| 397 |
+
return *val;
|
| 398 |
+
} else {
|
| 399 |
+
return std::forward<F>(f)();
|
| 400 |
+
}
|
| 401 |
+
```
|
| 402 |
+
|
| 403 |
+
#### Modifiers <a id="optional.ref.mod">[[optional.ref.mod]]</a>
|
| 404 |
+
|
| 405 |
+
``` cpp
|
| 406 |
+
constexpr void reset() noexcept;
|
| 407 |
+
```
|
| 408 |
+
|
| 409 |
+
*Effects:* Assigns `nullptr` to *val*.
|
| 410 |
+
|
| 411 |
+
*Ensures:* `*this` does not contain a value.
|
| 412 |
+
|
| 413 |
+
#### Exposition only helper functions <a id="optional.ref.expos">[[optional.ref.expos]]</a>
|
| 414 |
+
|
| 415 |
+
``` cpp
|
| 416 |
+
template<class U>
|
| 417 |
+
constexpr void convert-ref-init-val(U&& u); // exposition only
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
*Effects:* Creates a variable `r` as if by `T& r(std::forward<U>(u));`
|
| 421 |
+
and then initializes *val* with `addressof(r)`.
|
| 422 |
+
|