forked from cplusplus/fundamentals-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptional.html
847 lines (694 loc) · 51.7 KB
/
optional.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
<cxx-clause id="optional">
<h1>Optional objects</h1>
<cxx-section id="optional.general">
<h1>In general</h1>
<p>This subclause describes class template <code>optional</code> that represents <em>optional objects</em>. An <dfn>optional object for object types</dfn> is an object that contains the storage for another object and manages the lifetime of this contained object, if any. The contained object may be initialized after the optional object has been initialized, and may be destroyed before the optional object has been destroyed. The initialization state of the contained object is tracked by the optional object.</p>
</cxx-section>
<cxx-section id="optional.synop">
<h1>Header <code><experimental/optional></code> synopsis</h1>
<pre><code>namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
<cxx-ref insynopsis="" to="optional.object"></cxx-ref>
template <class T> class optional;
<cxx-ref insynopsis="" to="optional.inplace"></cxx-ref>
struct in_place_t{};
constexpr in_place_t in_place{};
<cxx-ref insynopsis="" to="optional.nullopt"></cxx-ref>
struct nullopt_t{<em>see below</em>};
constexpr nullopt_t nullopt(<em>unspecified</em>);
<cxx-ref insynopsis="" to="optional.bad_optional_access"></cxx-ref>
class bad_optional_access;
<cxx-ref insynopsis="" to="optional.relops"></cxx-ref>
template <class T>
constexpr bool operator==(const optional<T>&, const optional<T>&);
template <class T>
constexpr bool operator!=(const optional<T>&, const optional<T>&);
template <class T>
constexpr bool operator<(const optional<T>&, const optional<T>&);
template <class T>
constexpr bool operator>(const optional<T>&, const optional<T>&);
template <class T>
constexpr bool operator<=(const optional<T>&, const optional<T>&);
template <class T>
constexpr bool operator>=(const optional<T>&, const optional<T>&);
<cxx-ref insynopsis="" to="optional.nullops"></cxx-ref>
template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
<cxx-ref insynopsis="" to="optional.comp_with_t"></cxx-ref>
template <class T> constexpr bool operator==(const optional<T>&, const T&);
template <class T> constexpr bool operator==(const T&, const optional<T>&);
template <class T> constexpr bool operator!=(const optional<T>&, const T&);
template <class T> constexpr bool operator!=(const T&, const optional<T>&);
template <class T> constexpr bool operator<(const optional<T>&, const T&);
template <class T> constexpr bool operator<(const T&, const optional<T>&);
template <class T> constexpr bool operator<=(const optional<T>&, const T&);
template <class T> constexpr bool operator<=(const T&, const optional<T>&);
template <class T> constexpr bool operator>(const optional<T>&, const T&);
template <class T> constexpr bool operator>(const T&, const optional<T>&);
template <class T> constexpr bool operator>=(const optional<T>&, const T&);
template <class T> constexpr bool operator>=(const T&, const optional<T>&);
<cxx-ref insynopsis="" to="optional.specalg"></cxx-ref>
template <class T> void swap(optional<T>&, optional<T>&) noexcept(<em>see below</em>);
template <class T> constexpr optional<<em>see below</em>> make_optional(T&&);
} // <i>namespace fundamentals_v2</i>
} // <i>namespace experimental</i>
<cxx-ref insynopsis="" to="optional.hash"></cxx-ref>
template <class T> struct hash;
template <class T> struct hash<experimental::optional<T>>;
} // <i>namespace std</i></code></pre>
<p>A program that necessitates the instantiation of template <code>optional</code> for a reference type, or for possibly cv-qualified types <code>in_place_t</code> or <code>nullopt_t</code> is ill-formed.</p>
</cxx-section>
<cxx-section id="optional.object">
<h1><code>optional</code> for object types</h1>
<pre><code>template <class T>
class optional
{
public:
typedef T value_type;
<cxx-ref insynopsis="" to="optional.object.ctor"></cxx-ref>
constexpr optional() noexcept;
constexpr optional(nullopt_t) noexcept;
optional(const optional&);
optional(optional&&) noexcept(<em>see below</em>);
constexpr optional(const T&);
constexpr optional(T&&);
template <class... Args> constexpr explicit optional(in_place_t, Args&&...);
template <class U, class... Args>
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
template <class U> constexpr optional(U&&);
template <class U> constexpr optional(const optional<U>&);
template <class U> constexpr optional(optional<U>&&);
<cxx-ref insynopsis="" to="optional.object.dtor"></cxx-ref>
~optional();
<cxx-ref insynopsis="" to="optional.object.assign"></cxx-ref>
optional& operator=(nullopt_t) noexcept;
optional& operator=(const optional&);
optional& operator=(optional&&) noexcept(<em>see below</em>);
template <class U> optional& operator=(U&&);
template <class U> optional& operator=(const optional<U>&);
template <class U> optional& operator=(optional<U>&&);
template <class... Args> void emplace(Args&&...);
template <class U, class... Args>
void emplace(initializer_list<U>, Args&&...);
<cxx-ref insynopsis="" to="optional.object.swap"></cxx-ref>
void swap(optional&) noexcept(<em>see below</em>);
<cxx-ref insynopsis="" to="optional.object.observe"></cxx-ref>
constexpr T const* operator ->() const;
constexpr T* operator ->();
constexpr T const& operator *() const &;
constexpr T& operator *() &;
constexpr T&& operator *() &&;
constexpr const T&& operator *() const &&;
constexpr explicit operator bool() const noexcept;
constexpr T const& value() const &;
constexpr T& value() &;
constexpr T&& value() &&;
constexpr const T&& value() const &&;
template <class U> constexpr T value_or(U&&) const &;
template <class U> constexpr T value_or(U&&) &&;
private:
T* val; // <i>exposition only</i>
};</code></pre>
<p>
Any instance of <code>optional<T></code> at any given time either contains a value or does not contain a value.
When an instance of <code>optional<T></code> <dfn>contains a value</dfn>,
it means that an object of type <code>T</code>, referred to as the optional object's <dfn>contained value</dfn>,
is allocated within the storage of the optional object.
Implementations are not permitted to use additional storage, such as dynamic memory, to allocate its contained value.
The contained value shall be allocated in a region of the <code>optional<T></code> storage suitably aligned for the type <code>T</code>.
It is implementation-defined whether over-aligned types are supported (<cxx-ref in="cxx" to="basic.align"></cxx-ref>).
When an object of type <code>optional<T></code> is contextually converted to <code>bool</code>,
the conversion returns <code>true</code> if the object contains a value;
otherwise the conversion returns <code>false</code>.
</p>
<p>Member <code>val</code> is provided for exposition only. When an <code>optional<T></code> object contains a value, <code>val</code> points to the contained value.</p>
<p><code>T</code> shall be an object type and shall satisfy the requirements of <code>Destructible</code> (Table 24).</p>
<cxx-section id="optional.object.ctor">
<h1>Constructors</h1>
<cxx-function>
<cxx-signature>constexpr optional() noexcept;</cxx-signature>
<cxx-signature>constexpr optional(nullopt_t) noexcept;</cxx-signature>
<cxx-postconditions><code>*this</code> does not contain a value.</cxx-postconditions>
<cxx-remarks>No contained value is initialized.
For every object type <code>T</code> these constructors shall be <code>constexpr</code> constructors (<cxx-ref in="cxx" to="dcl.constexpr"></cxx-ref>).</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>optional(const optional<T>& <var>rhs</var>);</cxx-signature>
<cxx-requires><code>is_copy_constructible_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>If <code><var>rhs</var></code> contains a value, initializes the contained value as if
direct-non-list-initializing an object of type <code>T</code> with the expression <code>*<var>rhs</var></code>.</cxx-effects>
<cxx-postconditions><code>bool(<var>rhs</var>) == bool(*this)</code>.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
</cxx-function>
<cxx-function>
<cxx-signature>optional(optional<T>&& <var>rhs</var>) noexcept(<em>see below</em>);</cxx-signature>
<cxx-requires><code>is_move_constructible_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>If <code><var>rhs</var></code> contains a value, initializes the contained value as if
direct-non-list-initializing an object of type <code>T</code> with the expression <code>std::move(*<var>rhs</var>)</code>.
<code>bool(<var>rhs</var>)</code> is unchanged.</cxx-effects>
<cxx-postconditions><code>bool(<var>rhs</var>) == bool(*this)</code>.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>The expression inside <code>noexcept</code> is equivalent to:<pre><code>is_nothrow_move_constructible_v<T></code></pre></cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr optional(const T& <var>v</var>);</cxx-signature>
<cxx-requires><code>is_copy_constructible_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>Initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the expression <code><var>v</var></code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If <code>T</code>'s selected constructor is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr optional(T&& <var>v</var>);</cxx-signature>
<cxx-requires><code>is_move_constructible_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>Initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the expression <code>std::move(<var>v</var>)</code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If <code>T</code>'s selected constructor is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class... Args> constexpr explicit optional(in_place_t, Args&&... <var>args</var>);</cxx-signature>
<cxx-requires><code>is_constructible_v<T, Args&&...></code> is <code>true</code>.</cxx-requires>
<cxx-effects>Initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the arguments <code>std::forward<Args>(<var>args</var>)...</code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If <code>T</code>'s constructor selected for the initialization is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U, class... Args>
constexpr explicit optional(in_place_t, initializer_list<U> <var>il</var>, Args&&... <var>args</var>);</cxx-signature>
<cxx-requires><code>is_constructible_v<T, initializer_list<U>&, Args&&...></code> is <code>true</code>.</cxx-requires>
<cxx-effects>Initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the arguments <code><var>il</var>, std::forward<Args>(<var>args</var>)...</code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>The function shall not participate in overload resolution unless <code>is_constructible_v<T, initializer_list<U>&, Args&&...></code> is <code>true</code>.
If <code>T</code>'s constructor selected for the initialization is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.</cxx-remarks>
</cxx-function>
<cxx-note>The following constructors are conditionally specified as <code>explicit</code>. This is typically implemented by declaring two such constructors, of which at most one participates in overload resolution.</cxx-note>
<cxx-function>
<cxx-signature>template <class U>
constexpr optional(U&& v);</cxx-signature>
<cxx-effects>Initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the expression <code>std::forward<U>(v)</code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If <code>T</code>'s selected constructor is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.
This constructor shall not participate in overload resolution unless <code>is_constructible_v<T, U&&></code> is <code>true</code> and <code>U</code> is not the same type as <code>T</code>.
The constructor is <code>explicit</code> if and only if <code>is_convertible_v<U&&, T></code> is <code>false</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U>
constexpr optional(const optional<U>& rhs);</cxx-signature>
<cxx-effects>If <code>rhs</code> contains a value, initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the expression <code>*rhs</code>.</cxx-effects>
<cxx-postconditions><code>bool(rhs) == bool(*this)</code>.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If <code>T</code>'s selected constructor is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.
This constructor shall not participate in overload resolution unless <code>is_constructible_v<T, const U&></code> is <code>true</code>, <code>is_same<decay_t<U>, T></code> is <code>false</code>, <code>is_constructible_v<T, const optional<U>&></code> is <code>false</code> and <code>is_convertible_v<const optional<U>&, T></code> is <code>false</code>.
The constructor is <code>explicit</code> if and only if <code>is_convertible_v<const U&, T></code> is <code>false</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U>
constexpr optional(optional<U>&& rhs);</cxx-signature>
<cxx-effects>If <code>rhs</code> contains a value, initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the expression <code>std::move(*rhs)</code>. <code>bool(rhs)</code> is unchanged.</cxx-effects>
<cxx-postconditions><code>bool(rhs) == bool(*this)</code>.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If <code>T</code>'s selected constructor is a <code>constexpr</code> constructor, this constructor shall be a <code>constexpr</code> constructor.
This constructor shall not participate in overload resolution unless <code>is_constructible_v<T, U&&></code> is <code>true</code>, <code>is_same<decay_t<U>, T></code> is <code>false</code>, <code>is_constructible_v<T, optional<U>&&></code> is <code>false</code> and <code>is_convertible_v<optional<U>&&, T></code> is <code>false</code> and <code>U</code> is not the same type as <code>T</code>.
The constructor is <code>explicit</code> if and only if <code>is_convertible_v<U&&, T></code> is <code>false</code>.</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="optional.object.dtor">
<h1>Destructor</h1>
<cxx-function>
<cxx-signature>~optional();</cxx-signature>
<cxx-effects>If <code>is_trivially_destructible_v<T> != true</code> and <code>*this</code> contains a value, calls <code><var>val</var>->T::~T()</code>.</cxx-effects>
<cxx-remarks>If <code>is_trivially_destructible_v<T> == true</code> then this destructor shall be a trivial destructor.</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="optional.object.assign">
<h1>Assignment</h1>
<cxx-function>
<cxx-signature>optional<T>& operator=(nullopt_t) noexcept;</cxx-signature>
<cxx-effects>If <code>*this</code> contains a value, calls <code><var>val</var>->T::~T()</code> to destroy the contained value; otherwise no effect.</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
<cxx-postconditions><code>*this</code> does not contain a value.</cxx-postconditions>
</cxx-function>
<cxx-function>
<cxx-signature>optional<T>& operator=(const optional<T>& <var>rhs</var>);</cxx-signature>
<cxx-requires><code>is_copy_constructible_v<T></code> is <code>true</code> and <code>is_copy_assignable_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>
<table is="cxx-table" class="single-border column-rules">
<caption><code>optional::operator=(const optional&)</code> effects</caption>
<tr>
<th></th>
<th><code>*this</code> contains a value</th>
<th><code>*this</code> does not contain a value</th>
</tr>
<tr>
<th><code>rhs</code> contains a value</th>
<td>assigns <code>*rhs</code> to the contained value</td>
<td>initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with <code>*rhs</code></td>
</tr>
<tr>
<th><code>rhs</code> does not contain a value</th>
<td>destroys the contained value by calling <code>val->T::~T()</code></td>
<td>no effect</td>
</tr>
</table>
</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
<cxx-postconditions><code>bool(<var>rhs</var>) == bool(*this)</code>.</cxx-postconditions>
<cxx-remarks>
If any exception is thrown, the result of the expression <code>bool(*this)</code> remains unchanged.
If an exception is thrown during the call to <code>T</code>'s copy constructor, no effect.
If an exception is thrown during the call to <code>T</code>'s copy assignment,
the state of its contained value is as defined by the exception safety guarantee of <code>T</code>'s copy assignment.
</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>optional<T>& operator=(optional<T>&& <var>rhs</var>) noexcept(<em>see below</em>);</cxx-signature>
<cxx-requires><code>is_move_constructible_v<T></code> is <code>true</code> and <code>is_move_assignable_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>The result of the expression <code>bool(rhs)</code> remains unchanged.
<table is="cxx-table" class="single-border column-rules">
<caption><code>optional::operator=(optional&&)</code> effects</caption>
<tr>
<th></th>
<th><code>*this</code> contains a value</th>
<th><code>*this</code> does not contain a value</th>
</tr>
<tr>
<th><code>rhs</code> contains a value</th>
<td>assigns <code>std::move(*rhs)</code> to the contained value</td>
<td>initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with <code>std::move(*rhs)</code></td>
</tr>
<tr>
<th><code>rhs</code> does not contain a value</th>
<td>destroys the contained value by calling <code>val->T::~T()</code></td>
<td>no effect</td>
</tr>
</table>
</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
<cxx-postconditions><code>bool(<var>rhs</var>) == bool(*this)</code>.</cxx-postconditions>
<cxx-remarks>
<p>The expression inside <code>noexcept</code> is equivalent to: <pre><code>is_nothrow_move_assignable_v<T> && <w-br></w-br>is_nothrow_move_constructible_v<T></code></pre></p>
<p>
If any exception is thrown, the result of the expression <code>bool(*this)</code> remains unchanged.
If an exception is thrown during the call to <code>T</code>'s move constructor,
the state of <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s move constructor.
If an exception is thrown during the call to <code>T</code>'s move assignment,
the state of <code><var>*val</var></code> and <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s move assignment.
</p>
</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U> optional<T>& operator=(U&& <var>v</var>);</cxx-signature>
<cxx-requires><code>is_constructible_v<T, U></code> is <code>true</code> and <code>is_assignable_v<T&, U></code> is <code>true</code>.</cxx-requires>
<cxx-effects>If <code>*this</code> contains a value, assigns <code>std::forward<U>(<var>v</var>)</code> to the contained value; otherwise initializes the contained value as if direct-non-list-initializing object of type <code>T</code> with <code>std::forward<U>(<var>v</var>)</code>.</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-remarks>
<p>If any exception is thrown, the result of the expression <code>bool(*this)</code> remains unchanged. If an exception is thrown during the call to <code>T</code>'s constructor, the state of <code><var>v</var></code> is determined by the exception safety guarantee of <code>T</code>'s constructor. If an exception is thrown during the call to <code>T</code>'s assignment, the state of <code><var>*val</var></code> and <code><var>v</var></code> is determined by the exception safety guarantee of <code>T</code>'s assignment.</p>
<p>The function shall not participate in overload resolution unless
<code>decay_t<U></code> is not <code>nullopt_t</code> and <code>decay_t<U></code> is not a specialization of <code>optional</code>.</p>
</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U> optional<T>& operator=(const optional<U>& rhs);</cxx-signature>
<cxx-requires><code>is_constructible_v<T, const U&></code> is <code>true</code> and <code>is_assignable_v<T&, const U&></code> is <code>true</code>.</cxx-requires>
<cxx-effects>
<table is="cxx-table" class="single-border column-rules">
<caption><code>optional::operator=(const optional<U>&)</code> effects</caption>
<tr>
<th></th>
<th><code>*this</code> contains a value</th>
<th><code>*this</code> does not contain a value</th>
</tr>
<tr>
<th><code>rhs</code> contains a value</th>
<td>assigns <code>*rhs</code> to the contained value</td>
<td>initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with <code>*rhs</code></td>
</tr>
<tr>
<th><code>rhs</code> does not contain a value</th>
<td>destroys the contained value by calling <code>val->T::~T()</code></td>
<td>no effect</td>
</tr>
</table>
</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
<cxx-postconditions><code>bool(rhs) == bool(*this)</code>.</cxx-postconditions>
<cxx-remarks>If any exception is thrown, the result of the expression <code>bool(*this)</code> remains unchanged.
If an exception is thrown during the call to <code>T</code>'s constructor, the state of <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s constructor.
If an exception is thrown during the call to <code>T</code>'s assignment, the state of <code>*val</code> and <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s assignment.
The function shall not participate in overload resolution unless <code>is_same_v<decay_t<U>, T></code> is <code>false</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U> optional<T>& operator=(optional<U>&& rhs);</cxx-signature>
<cxx-requires><code>is_constructible_v<T, U></code> is <code>true</code> and <code>is_assignable_v<T&, U></code> is <code>true</code>.</cxx-requires>
<cxx-effects>The result of the expression <code>bool(rhs)</code> remains unchanged.
<table is="cxx-table" class="single-border column-rules">
<caption><code>optional::operator=(optional<U>&&)</code> effects</caption>
<tr>
<th></th>
<th><code>*this</code> contains a value</th>
<th><code>*this</code> does not contain a value</th>
</tr>
<tr>
<th><code>rhs</code> contains a value</th>
<td>assigns <code>std::move(*rhs)</code> to the contained value</td>
<td>initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with <code>std::move(*rhs)</code></td>
</tr>
<tr>
<th><code>rhs</code> does not contain a value</th>
<td>destroys the contained value by calling <code>val->T::~T()</code></td>
<td>no effect</td>
</tr>
</table>
</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
<cxx-postconditions><code>bool(rhs) == bool(*this)</code>.</cxx-postconditions>
<cxx-remarks>If any exception is thrown, the result of the expression <code>bool(*this)</code> remains unchanged.
If an exception is thrown during the call to <code>T</code>'s constructor, the state of <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s constructor.
If an exception is thrown during the call to <code>T</code>'s assignment, the state of <code>*val</code> and <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s assignment.
The function shall not participate in overload resolution unless <code>is_same_v<decay_t<U>, T></code> is false.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class... Args> void emplace(Args&&... <var>args</var>);</cxx-signature>
<cxx-requires><code>is_constructible_v<T, Args&&...></code> is <code>true</code>.</cxx-requires>
<cxx-effects>Calls <code>*this = nullopt</code>. Then initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the arguments <code>std::forward<Args>(<var>args</var>)...</code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>If an exception is thrown during the call to <code>T</code>'s constructor, <code>*this</code> does not contain a value, and the previous <code><var>*val</var></code> (if any) has been destroyed.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U, class... Args> <w-br></w-br>void emplace(initializer_list<U> <var>il</var>, Args&&... <var>args</var>);</cxx-signature>
<cxx-effects>Calls <code>*this = nullopt</code>. Then initializes the contained value as if direct-non-list-initializing an object of type <code>T</code> with the arguments <code><var>il</var>, std::forward<Args>(<var>args</var>)...</code>.</cxx-effects>
<cxx-postconditions><code>*this</code> contains a value.</cxx-postconditions>
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
<cxx-remarks>
<p>If an exception is thrown during the call to <code>T</code>'s constructor, <code>*this</code> does not contain a value, and the previous <code><var>*val</var></code> (if any) has been destroyed.</p>
<p>The function shall not participate in overload resolution unless <code>is_constructible_v<T, initializer_list<U>&, Args&&...></code> is <code>true</code>.</p>
</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="optional.object.swap">
<h1>Swap</h1>
<cxx-function>
<cxx-signature>void swap(optional<T>& <var>rhs</var>) noexcept(<em>see below</em>);</cxx-signature>
<cxx-requires>Lvalues of type <code>T</code> shall be swappable and <code>is_move_constructible_v<T></code> is <code>true</code>.</cxx-requires>
<cxx-effects>
<table is="cxx-table" class="single-border column-rules">
<caption><code>optional::swap(optional&)</code> effects</caption>
<tr>
<th></th>
<th><code>*this</code> contains a value</th>
<th><code>*this</code> does not contain a value</th>
</tr>
<tr>
<th><code>rhs</code> contains a value</th>
<td>calls <code>swap(*(*this), *<var>rhs</var>)</code></td>
<td>initializes the contained value of <code>*this</code> as if
direct-non-list-initializing an object of type <code>T</code> with the expression <code>std::move(*<var>rhs</var>)</code>,
followed by <code>rhs.val->T::~T()</code>;
postcondition is that <code>*this</code> contains a value and <code><var>rhs</var></code> does not contain a value</td>
</tr>
<tr><th><code>rhs</code> does not contain a value</th>
<td>initializes the contained value of <code><var>rhs</var></code> as if
direct-non-list-initializing an object of type <code>T</code> with the expression <code>std::move(*(*this))</code>,
followed by <code>val->T::~T()</code>;
postcondition is that <code>*this</code> does not contain a value and <code><var>rhs</var></code> contains a value</td>
<td>no effect</td>
</tr>
</table>
</cxx-effects>
<cxx-throws>Any exceptions that the expressions in the Effects element throw.</cxx-throws>
<cxx-remarks>
<p>The expression inside <code>noexcept</code> is equivalent to: <pre><code>is_nothrow_move_constructible_v<T> && <w-br></w-br>noexcept(swap(declval<T&>(), declval<T&>()))</code></pre></p>
<p>
If any exception is thrown, the results of the expressions <code>bool(*this)</code> and <code>bool(<var>rhs</var>)</code> remain unchanged.
If an exception is thrown during the call to function <code>swap</code>
the state of <code><var>*val</var></code> and <code>*rhs.val</code> is determined by the exception safety guarantee of <code>swap</code> for lvalues of <code>T</code>.
If an exception is thrown during the call to <code>T</code>'s move constructor,
the state of <code><var>*val</var></code> and <code>*rhs.val</code> is determined by the exception safety guarantee of <code>T</code>'s move constructor.
</p>
</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="optional.object.observe">
<h1>Observers</h1>
<cxx-function>
<cxx-signature>constexpr T const* operator->() const;</cxx-signature>
<cxx-signature>constexpr T* operator->();</cxx-signature>
<cxx-requires><code>*this</code> contains a value.</cxx-requires>
<cxx-returns><code><var>val</var></code>.</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
<cxx-remarks>Unless <code>T</code> is a user-defined type with overloaded unary <code>operator&</code>, these functions shall be <code>constexpr</code> functions.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr T const& operator*() const &;</cxx-signature>
<cxx-signature>constexpr T& operator*() &;</cxx-signature>
<cxx-requires><code>*this</code> contains a value.</cxx-requires>
<cxx-returns><code>*<var>val</var></code>.</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
<cxx-remarks>These functions shall be <code>constexpr</code> functions.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr T&& operator*() &&;</cxx-signature>
<cxx-signature>constexpr const T&& operator*() const &&;</cxx-signature>
<cxx-requires><code>*this</code> contains a value.</cxx-requires>
<cxx-effects>Equivalent to <code>return std::move(*<var>val</var>);</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr explicit operator bool() const noexcept;</cxx-signature>
<cxx-returns><code>true</code> if and only if <code>*this</code> contains a value.</cxx-returns>
<cxx-remarks>This function shall be a <code>constexpr</code> function.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr T const& value() const &;</cxx-signature>
<cxx-signature>constexpr T& value() &;</cxx-signature>
<cxx-effects>Equivalent to <code>return bool(*this) ? *val : throw bad_optional_access();</code></cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr T&& value() &&;</cxx-signature>
<cxx-signature>constexpr const T&& value() const &&;</cxx-signature>
<cxx-effects>Equivalent to <code>return bool(*this) ? std::move(*val) : throw bad_optional_access();</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U> constexpr T value_or(U&& <var>v</var>) const &;</cxx-signature>
<cxx-effects>Equivalent to <code>return bool(*this) ? **this : static_cast<T>(std::forward<U>(<var>v</var>));</code></cxx-effects>
<cxx-remarks>If <code>is_copy_constructible_v<T> && <w-br></w-br>is_convertible_v<U&&, T></code> is <code>false</code>,
the program is ill-formed.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U> T value_or(U&& <var>v</var>) &&;</cxx-signature>
<cxx-effects>Equivalent to <code>return bool(*this) ? <w-br></w-br>std::move(**this) : <w-br></w-br>static_cast<T>(std::forward<U>(<var>v</var>));</code></cxx-effects>
<cxx-remarks>If <code>is_move_constructible_v<T> && <w-br></w-br>is_convertible_v<U&&, T></code> is <code>false</code>,
the program is ill-formed.</cxx-remarks>
</cxx-function>
</cxx-section>
</cxx-section>
<cxx-section id="optional.inplace">
<h1>In-place construction</h1>
<cxx-function>
<cxx-signature>struct in_place_t{};</cxx-signature>
<cxx-signature>constexpr in_place_t in_place{};</cxx-signature>
</cxx-function>
<p>
The struct <code>in_place_t</code> is an empty structure type used as a unique type to disambiguate constructor and function overloading.
Specifically, <code>optional<T></code> has a constructor with <code>in_place_t</code> as the first parameter followed by a parameter pack;
this indicates that <code>T</code> should be constructed in-place (as if by a call to a placement new expression) with the forwarded pack expansion as arguments for the initialization of <code>T</code>.
</p>
</cxx-section>
<cxx-section id="optional.nullopt">
<h1>No-value state indicator</h1>
<cxx-function>
<cxx-signature>struct nullopt_t{<em>see below</em>};</cxx-signature>
<cxx-signature>constexpr nullopt_t nullopt(<em>unspecified</em>);</cxx-signature>
</cxx-function>
<p>The struct <code>nullopt_t</code> is an empty structure type used as a unique type to indicate the state of not containing a value for <code>optional</code> objects.
In particular, <code>optional<T></code> has a constructor with <code>nullopt_t</code> as a single argument;
this indicates that an optional object not containing a value shall be constructed.
</p>
<p>Type <code>nullopt_t</code> shall not have a default constructor. It shall be a literal type. Constant <code>nullopt</code> shall be initialized with an argument of literal type.</p>
</cxx-section>
<cxx-section id="optional.bad_optional_access">
<h1>Class <code>bad_optional_access</code></h1>
<pre><code>class bad_optional_access : public logic_error {
public:
bad_optional_access();
};</code></pre>
<p>The class <code>bad_optional_access</code> defines the type of objects thrown as exceptions to report the situation where an attempt is made to access the value of an optional object that does not contain a value.</p>
<cxx-function>
<cxx-signature>bad_optional_access();</cxx-signature>
<cxx-effects>Constructs an object of class <code>bad_optional_access</code>.</cxx-effects>
<cxx-postconditions><code>what()</code> returns an implementation-defined NTBS.</cxx-postconditions>
</cxx-function>
</cxx-section>
<cxx-section id="optional.relops">
<h1>Relational operators</h1>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator==(const optional<T>& <var>x</var>, const optional<T>& <var>y</var>);</cxx-signature>
<cxx-requires><code>T</code> shall meet the requirements of <code>EqualityComparable</code>.</cxx-requires>
<cxx-returns>If <code>bool(<var>x</var>) != bool(<var>y</var>)</code>, <code>false</code>; otherwise if <code>bool(<var>x</var>) == false</code>, <code>true</code>; otherwise <code>*<var>x</var> == *<var>y</var></code>.</cxx-returns>
<cxx-remarks>Specializations of this function template,
for which <code>*<var>x</var> == *<var>y</var></code> is a core constant expression,
shall be <code>constexpr</code> functions.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator!=(const optional<T>& x, const optional<T>& y);</cxx-signature>
<cxx-returns><code>!(x == y)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<(const optional<T>& <var>x</var>, const optional<T>& <var>y</var>);</cxx-signature>
<cxx-requires><code>*<var>x</var> < *<var>y</var></code> shall be well-formed
and its result shall be convertible to <code>bool</code>.</cxx-requires>
<cxx-returns>If <code>!<var>y</var></code>, <code>false</code>;
otherwise, if <code>!<var>x</var></code>, <code>true</code>;
otherwise <code>*<var>x</var> < *<var>y</var></code>.</cxx-returns>
<cxx-remarks>Specializations of this function template,
for which <code>*<var>x</var> < *<var>y</var></code> is a core constant expression,
shall be <code>constexpr</code> functions.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>(const optional<T>& x, const optional<T>& y);</cxx-signature>
<cxx-returns><code>y < x</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<=(const optional<T>& x, const optional<T>& y);</cxx-signature>
<cxx-returns><code>!(y < x)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>=(const optional<T>& x, const optional<T>& y);</cxx-signature>
<cxx-returns><code>!(x < y)</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="optional.nullops">
<h1>Comparison with <code>nullopt</code></h1>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator==(const optional<T>& <var>x</var>, nullopt_t) noexcept;</cxx-signature>
<cxx-signature>template <class T> constexpr bool operator==(nullopt_t, const optional<T>& <var>x</var>) noexcept;</cxx-signature>
<cxx-returns><code>!<var>x</var></code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator!=(const optional<T>& <var>x</var>, nullopt_t) noexcept;</cxx-signature>
<cxx-signature>template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept;</cxx-signature>
<cxx-returns><code>bool(<var>x</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<(const optional<T>& <var>x</var>, nullopt_t) noexcept;</cxx-signature>
<cxx-returns><code>false</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<(nullopt_t, const optional<T>& <var>x</var>) noexcept;</cxx-signature>
<cxx-returns><code>bool(<var>x</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<=(const optional<T>& <var>x</var>, nullopt_t) noexcept;</cxx-signature>
<cxx-returns><code>!<var>x</var></code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<=(nullopt_t, const optional<T>& <var>x</var>) noexcept;</cxx-signature>
<cxx-returns><code>true</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>(const optional<T>& <var>x</var>, nullopt_t) noexcept;</cxx-signature>
<cxx-returns><code>bool(<var>x</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>(nullopt_t, const optional<T>& <var>x</var>) noexcept;</cxx-signature>
<cxx-returns><code>false</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>=(const optional<T>& <var>x</var>, nullopt_t) noexcept;</cxx-signature>
<cxx-returns><code>true</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& <var>x</var>) noexcept;</cxx-signature>
<cxx-returns><code>!<var>x</var></code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="optional.comp_with_t">
<h1>Comparison with <code>T</code></h1>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator==(const optional<T>& <var>x</var>, const T& <var>v</var>);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? *<var>x</var> == <var>v</var> : false</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator==(const T& <var>v</var>, const optional<T>& x);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? <var>v</var> == *<var>x</var> : false</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator!=(const optional<T>& <var>x</var>, const T& <var>v</var>);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? !(*<var>x</var> == <var>v</var>) : true</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator!=(const T& <var>v</var>, const optional<T>& x);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? !(<var>v</var> == *<var>x</var>) : true</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<(const optional<T>& <var>x</var>, const T& <var>v</var>);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? *<var>x</var> < <var>v</var> : true</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<(const T& <var>v</var>, const optional<T>& <var>x</var>);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? <var>v</var> < *<var>x</var> : false</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<=(const optional<T>& <var>x</var>, const T& <var>v</var>);</cxx-signature>
<cxx-returns><code>!(<var>x</var> > <var>v</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator<=(const T& <var>v</var>, const optional<T>& x);</cxx-signature>
<cxx-returns><code>!(<var>v</var> > <var>x</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>(const optional<T>& <var>x</var>, const T& <var>v</var>);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? <var>v</var> < *<var>x</var> : false</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>(const T& <var>v</var>, const optional<T>& x);</cxx-signature>
<cxx-returns><code>bool(<var>x</var>) ? *<var>x</var> < <var>v</var> : true</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>=(const optional<T>& <var>x</var>, const T& <var>v</var>);</cxx-signature>
<cxx-returns><code>!(<var>x</var> < <var>v</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr bool operator>=(const T& <var>v</var>, const optional<T>& x);</cxx-signature>
<cxx-returns><code>!(<var>v</var> < <var>x</var>)</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="optional.specalg">
<h1>Specialized algorithms</h1>
<cxx-function>
<cxx-signature>template <class T> void swap(optional<T>& <var>x</var>, optional<T>& <var>y</var>) noexcept(noexcept(<var>x</var>.swap(<var>y</var>)));</cxx-signature>
<cxx-effects>Calls <code><var>x</var>.swap(<var>y</var>)</code>.</cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>template <class T> constexpr optional<decay_t<T>> make_optional(T&& <var>v</var>);</cxx-signature>
<cxx-returns><code>optional<decay_t<T>>(std::forward<T>(<var>v</var>))</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="optional.hash">
<h1>Hash support</h1>
<cxx-function>
<cxx-signature>template <class T> struct hash<experimental::optional<T>>;</cxx-signature>
<cxx-requires>The template specialization <code>hash<T></code> shall meet the requirements of class template <code>hash</code> (<cxx-ref in="cxx" to="unord.hash"></cxx-ref>).
The template specialization <code>hash<optional<T>></code> shall meet the requirements of class template <code>hash</code>.
For an object <code><var>o</var></code> of type <code>optional<T></code>, if <code>bool(<var>o</var>) == true</code>,
<code>hash<optional<T>>()(<var>o</var>)</code> shall evaluate to the same value as <code>hash<T>()(*<var>o</var>)</code>;
otherwise it evaluates to an unspecified value.</cxx-requires>
</cxx-function>
</cxx-section>
</cxx-clause>