forked from cplusplus/fundamentals-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.html
1361 lines (1136 loc) · 56.9 KB
/
utilities.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
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<cxx-clause id="utilities">
<h1>General utilities library</h1>
<cxx-section id="utility">
<h1>Utility components</h1>
<cxx-section id="utility.synop">
<h1>Header <code><experimental/utility></code> synopsis</h1>
<pre><code>#include <utility>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
<cxx-ref insynopsis="" to="utility.erased.type"></cxx-ref>
struct erased_type { };
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="utility.erased.type">
<h1>Class <code>erased_type</code></h1>
<cxx-function>
<cxx-signature>struct erased_type { };</cxx-signature>
<p>
The <code>erased_type</code> <code>struct</code> is an empty <code>struct</code> that serves as a placeholder for a type <code>T</code> in situations where the actual type <code>T</code> is determined at runtime.
For example, the nested type, <code>allocator_type</code>, is an alias for <code>erased_type</code> in classes that use <i>type-erased allocators</i> (see <cxx-ref to="memory.type.erased.allocator"></cxx-ref>).
</p>
</cxx-function>
</cxx-section>
</cxx-section>
<cxx-section id="tuple">
<h1>Tuples</h1>
<cxx-section id="header.tuple.synop">
<h1>Header <experimental/tuple> synopsis</h1>
<pre><code>#include <tuple>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
// See <cxx-ref in="cxx" to="tuple.helper"></cxx-ref>, tuple helper classes
template <class T> constexpr size_t tuple_size_v
= tuple_size<T>::value;
<cxx-ref insynopsis="" to="tuple.apply"></cxx-ref>
template <class F, class Tuple>
constexpr decltype(auto) apply(F&& f, Tuple&& t);
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="tuple.apply">
<h1>Calling a function with a <code>tuple</code> of arguments</h1>
<cxx-function>
<cxx-signature>template <class F, class Tuple>
constexpr decltype(auto) apply(F&& f, Tuple&& t);</cxx-signature>
<cxx-effects>
<p>Given the exposition only function</p>
<pre><code>template <class F, class Tuple, size_t... I>
constexpr decltype(auto) apply_impl( // <i>exposition only</i>
F&& f, Tuple&& t, index_sequence<I...>) {
return <em>INVOKE</em>(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))...);
}</code></pre>
<p>Equivalent to</p>
<pre><code>return apply_impl(std::forward<F>(f), std::forward<Tuple>(t),
make_index_sequence<tuple_size_v<decay_t<Tuple>>>{});</code></pre>
</cxx-effects>
</cxx-function>
</cxx-section>
</cxx-section>
<cxx-section id="meta">
<h1>Metaprogramming and type traits</h1>
<cxx-section id="meta.type.synop">
<h1>Header <experimental/type_traits> synopsis</h1>
<pre><code>#include <type_traits>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
// See <cxx-ref in="cxx" to="meta.unary.cat"></cxx-ref>, primary type categories
template <class T> constexpr bool is_void_v
= is_void<T>::value;
template <class T> constexpr bool is_null_pointer_v
= is_null_pointer<T>::value;
template <class T> constexpr bool is_integral_v
= is_integral<T>::value;
template <class T> constexpr bool is_floating_point_v
= is_floating_point<T>::value;
template <class T> constexpr bool is_array_v
= is_array<T>::value;
template <class T> constexpr bool is_pointer_v
= is_pointer<T>::value;
template <class T> constexpr bool is_lvalue_reference_v
= is_lvalue_reference<T>::value;
template <class T> constexpr bool is_rvalue_reference_v
= is_rvalue_reference<T>::value;
template <class T> constexpr bool is_member_object_pointer_v
= is_member_object_pointer<T>::value;
template <class T> constexpr bool is_member_function_pointer_v
= is_member_function_pointer<T>::value;
template <class T> constexpr bool is_enum_v
= is_enum<T>::value;
template <class T> constexpr bool is_union_v
= is_union<T>::value;
template <class T> constexpr bool is_class_v
= is_class<T>::value;
template <class T> constexpr bool is_function_v
= is_function<T>::value;
// See <cxx-ref in="cxx" to="meta.unary.comp"></cxx-ref>, composite type categories
template <class T> constexpr bool is_reference_v
= is_reference<T>::value;
template <class T> constexpr bool is_arithmetic_v
= is_arithmetic<T>::value;
template <class T> constexpr bool is_fundamental_v
= is_fundamental<T>::value;
template <class T> constexpr bool is_object_v
= is_object<T>::value;
template <class T> constexpr bool is_scalar_v
= is_scalar<T>::value;
template <class T> constexpr bool is_compound_v
= is_compound<T>::value;
template <class T> constexpr bool is_member_pointer_v
= is_member_pointer<T>::value;
// See <cxx-ref in="cxx" to="meta.unary.prop"></cxx-ref>, type properties
template <class T> constexpr bool is_const_v
= is_const<T>::value;
template <class T> constexpr bool is_volatile_v
= is_volatile<T>::value;
template <class T> constexpr bool is_trivial_v
= is_trivial<T>::value;
template <class T> constexpr bool is_trivially_copyable_v
= is_trivially_copyable<T>::value;
template <class T> constexpr bool is_standard_layout_v
= is_standard_layout<T>::value;
template <class T> constexpr bool is_pod_v
= is_pod<T>::value;
template <class T> constexpr bool is_literal_type_v
= is_literal_type<T>::value;
template <class T> constexpr bool is_empty_v
= is_empty<T>::value;
template <class T> constexpr bool is_polymorphic_v
= is_polymorphic<T>::value;
template <class T> constexpr bool is_abstract_v
= is_abstract<T>::value;
template <class T> constexpr bool is_final_v
= is_final<T>::value;
template <class T> constexpr bool is_signed_v
= is_signed<T>::value;
template <class T> constexpr bool is_unsigned_v
= is_unsigned<T>::value;
template <class T, class... Args> constexpr bool is_constructible_v
= is_constructible<T, Args...>::value;
template <class T> constexpr bool is_default_constructible_v
= is_default_constructible<T>::value;
template <class T> constexpr bool is_copy_constructible_v
= is_copy_constructible<T>::value;
template <class T> constexpr bool is_move_constructible_v
= is_move_constructible<T>::value;
template <class T, class U> constexpr bool is_assignable_v
= is_assignable<T, U>::value;
template <class T> constexpr bool is_copy_assignable_v
= is_copy_assignable<T>::value;
template <class T> constexpr bool is_move_assignable_v
= is_move_assignable<T>::value;
template <class T> constexpr bool is_destructible_v
= is_destructible<T>::value;
template <class T, class... Args> constexpr bool is_trivially_constructible_v
= is_trivially_constructible<T, Args...>::value;
template <class T> constexpr bool is_trivially_default_constructible_v
= is_trivially_default_constructible<T>::value;
template <class T> constexpr bool is_trivially_copy_constructible_v
= is_trivially_copy_constructible<T>::value;
template <class T> constexpr bool is_trivially_move_constructible_v
= is_trivially_move_constructible<T>::value;
template <class T, class U> constexpr bool is_trivially_assignable_v
= is_trivially_assignable<T, U>::value;
template <class T> constexpr bool is_trivially_copy_assignable_v
= is_trivially_copy_assignable<T>::value;
template <class T> constexpr bool is_trivially_move_assignable_v
= is_trivially_move_assignable<T>::value;
template <class T> constexpr bool is_trivially_destructible_v
= is_trivially_destructible<T>::value;
template <class T, class... Args> constexpr bool is_nothrow_constructible_v
= is_nothrow_constructible<T, Args...>::value;
template <class T> constexpr bool is_nothrow_default_constructible_v
= is_nothrow_default_constructible<T>::value;
template <class T> constexpr bool is_nothrow_copy_constructible_v
= is_nothrow_copy_constructible<T>::value;
template <class T> constexpr bool is_nothrow_move_constructible_v
= is_nothrow_move_constructible<T>::value;
template <class T, class U> constexpr bool is_nothrow_assignable_v
= is_nothrow_assignable<T, U>::value;
template <class T> constexpr bool is_nothrow_copy_assignable_v
= is_nothrow_copy_assignable<T>::value;
template <class T> constexpr bool is_nothrow_move_assignable_v
= is_nothrow_move_assignable<T>::value;
template <class T> constexpr bool is_nothrow_destructible_v
= is_nothrow_destructible<T>::value;
template <class T> constexpr bool has_virtual_destructor_v
= has_virtual_destructor<T>::value;
// See <cxx-ref in="cxx" to="meta.unary.prop.query"></cxx-ref>, type property queries
template <class T> constexpr size_t alignment_of_v
= alignment_of<T>::value;
template <class T> constexpr size_t rank_v
= rank<T>::value;
template <class T, unsigned I = 0> constexpr size_t extent_v
= extent<T, I>::value;
// See <cxx-ref in="cxx" to="meta.rel"></cxx-ref>, type relations
template <class T, class U> constexpr bool is_same_v
= is_same<T, U>::value;
template <class Base, class Derived> constexpr bool is_base_of_v
= is_base_of<Base, Derived>::value;
template <class From, class To> constexpr bool is_convertible_v
= is_convertible<From, To>::value;
<cxx-ref insynopsis="" to="meta.trans.other"></cxx-ref>
template <class> class invocation_type; // <i>not defined</i>
template <class F, class... ArgTypes> class invocation_type<F(ArgTypes...)>;
template <class> class raw_invocation_type; // <i>not defined</i>
template <class F, class... ArgTypes> class raw_invocation_type<F(ArgTypes...)>;
template <class T>
using invocation_type_t = typename invocation_type<T>::type;
template <class T>
using raw_invocation_type_t = typename raw_invocation_type<T>::type;
<cxx-ref insynopsis="" to="meta.logical"></cxx-ref>
template<class... B> struct conjunction;
template<class... B> constexpr bool conjunction_v = conjunction<B...>::value;
template<class... B> struct disjunction;
template<class... B> constexpr bool disjunction_v = disjunction<B...>::value;
template<class B> struct negation;
template<class B> constexpr bool negation_v = negation<B>::value;
<cxx-ref insynopsis to="meta.detect"></cxx-ref>
template <class...> using void_t = void;
struct nonesuch {
nonesuch() = delete;
~nonesuch() = delete;
nonesuch(nonesuch const&) = delete;
void operator=(nonesuch const&) = delete;
};
template <template<class...> class Op, class... Args>
using is_detected = <i>see below</i>;
template <template<class...> class Op, class... Args>
constexpr bool is_detected_v = is_detected<Op, Args...>::value;
template <template<class...> class Op, class... Args>
using detected_t = <i>see below</i>;
template <class Default, template<class...> class Op, class... Args>
using detected_or = <i>see below</i>;
template <class Default, template<class...> class Op, class... Args>
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
template <class Expected, template<class...> class Op, class... Args>
using is_detected_exact = is_same<Expected, detected_t<Op, Args...>>;
template <class Expected, template<class...> class Op, class... Args>
constexpr bool is_detected_exact_v
= is_detected_exact<Expected, Op, Args...>::value;
template <class To, template<class...> class Op, class... Args>
using is_detected_convertible = is_convertible<detected_t<Op, Args...>, To>;
template <class To, template<class...> class Op, class... Args>
constexpr bool is_detected_convertible_v
= is_detected_convertible<To, Op, Args...>::value;
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="meta.trans.other">
<h1>Other type transformations</h1>
<p>
This sub-clause contains templates that may be used to transform one type to another following some predefined rule.
</p>
<p>
Each of the templates in this subclause shall be a <cxx-term>TransformationTrait</cxx-term> (<cxx-ref in="cxx" to="meta.rqmts"></cxx-ref>).
</p>
<p>
Within this section, define the <dfn>invocation parameters</dfn> of <code><em>INVOKE</em>(f, t1, t2, ..., tN)</code> as follows,
in which <code>T1</code> is the possibly <var>cv</var>-qualified type of <code>t1</code>
and <code>U1</code> denotes <code>T1&</code> if <code>t1</code> is an lvalue
or <code>T1&&</code> if <code>t1</code> is an rvalue:
</p>
<ul>
<li>
When <code>f</code> is a pointer to a member function of a class <code>T</code>
the <cxx-term>invocation parameters</cxx-term> are <code>U1</code> followed by
the parameters of <code>f</code> matched by <code>t2</code>, ..., <code>tN</code>.
</li>
<li>
When <code>N == 1</code> and <code>f</code> is a pointer to member data of a class <code>T</code>
the <cxx-term>invocation parameter</cxx-term> is <code>U1</code>.
</li>
<li>
If <code>f</code> is a class object,
the <cxx-term>invocation parameters</cxx-term> are the parameters matching <code>t1</code>, ..., <code>tN</code>
of the best viable function (<cxx-ref in="cxx" to="over.match.best"></cxx-ref>)
for the arguments <code>t1</code>, ..., <code>tN</code>
among the function call operators and surrogate call functions of <code>f</code>.
</li>
<li>
In all other cases,
the <cxx-term>invocation parameters</cxx-term> are the parameters of <code>f</code>
matching <code>t1</code>, ... <code>tN</code>.
</li>
</ul>
<p>
In all of the above cases,
if an argument <code>tI</code> matches the ellipsis in the function's <cxx-term>parameter-declaration-clause</cxx-term>,
the corresponding <cxx-term>invocation parameter</cxx-term> is defined to be
the result of applying the default argument promotions (<cxx-ref in="cxx" to="expr.call"></cxx-ref>) to <code>tI</code>.
</p>
<cxx-example>
Assume <code>S</code> is defined as
<pre><code>struct S {
int f(double const &) const;
void operator()(int, int);
void operator()(char const *, int i = 2, int j = 3);
void operator()(...);
};</code></pre>
<ul>
<li>The invocation parameters of <code><em>INVOKE</em>(&S::f, S(), 3.5)</code> are <code>(S &&, double const &)</code>.</li>
<li>The invocation parameters of <code><em>INVOKE</em>(S(), 1, 2)</code> are <code>(int, int)</code>.</li>
<li>The invocation parameters of <code><em>INVOKE</em>(S(), "abc", 5)</code> are <code>(const char *, int)</code>.
The defaulted parameter <code>j</code> does not correspond to an argument.</li>
<li>The invocation parameters of <code><em>INVOKE</em>(S(), locale(), 5)</code> are <code>(locale, int)</code>.
Arguments corresponding to ellipsis maintain their types.</li>
</ul>
</cxx-example>
<table is="cxx-table" id="tab:meta.trans.other">
<caption>Other type transformations</caption>
<thead>
<tr><th>Template</th><th>Condition</th><th>Comments</th></tr>
</thead>
<tr>
<td>
<code>template <class Fn, class... ArgTypes><br/>
struct raw_invocation_type<<w-br></w-br>Fn(ArgTypes...)>;</code>
</td>
<td>
<code>Fn</code> and all types in the parameter pack <code>ArgTypes</code>
shall be complete types, (possibly cv-qualified) <code>void</code>, or arrays of unknown bound.
</td>
<td>
<em>see below</em>
</td>
</tr>
<tr>
<td>
<code>template <class Fn, class... ArgTypes><br/>
struct invocation_type<<w-br></w-br>Fn(ArgTypes...)>;</code>
</td>
<td>
<code>Fn</code> and all types in the parameter pack <code>ArgTypes</code>
shall be complete types, (possibly cv-qualified) <code>void</code>,
or arrays of unknown bound.
</td>
<td>
<em>see below</em>
</td>
</tr>
</table>
<p>
Access checking is performed as if in a context unrelated to <code>Fn</code> and <code>ArgTypes</code>.
Only the validity of the immediate context of the expression is considered.
<cxx-note>The compilation of the expression can result in side effects
such as the instantiation of class template specializations and function template specializations,
the generation of implicitly-defined functions, and so on.
Such side effects are not in the "immediate context"
and can result in the program being ill-formed.</cxx-note>
</p>
<p>
The nested typedef <code>raw_invocation_type<Fn(ArgTypes...)>::type</code> shall be defined as follows.
If the expression <code><em>INVOKE</em>(declval<Fn>(), declval<ArgTypes>()...)</code>
is ill-formed when treated as an unevaluated operand (<cxx-ref in="cxx" to="expr"></cxx-ref>),
there shall be no member <code>type</code>. Otherwise:
</p>
<ul>
<li>Let <code>R</code> denote <code>result_of_t<Fn(ArgTypes...)></code>.</li>
<li>Let the types <code>Ti</code> be the <cxx-term>invocation parameters</cxx-term>
of <code><em>INVOKE</em>(declval<Fn>(), <nobr>declval<ArgTypes>()...)</code></nobr>.</li>
<li>Then the member typedef <code>type</code> shall name the function type <code>R(T1, T2, ...)</code>.</li>
</ul>
<p>
The nested typedef <code>invocation_type<Fn(ArgTypes...)>::type</code> shall be defined as follows.
If <code>raw_invocation_type<Fn(ArgTypes...)>::type</code> does not exist, there shall be no member typedef <code>type</code>.
Otherwise:
</p>
<ul>
<li>Let <code>A1, A2,</code> … denote <code>ArgTypes...</code></li>
<li>Let <code>R(T1, T2, …)</code> denote <code>raw_invocation_type_t<Fn(ArgTypes...)></code></li>
<li>
Then the member typedef <code>type</code> shall name the function type <code>R(U1, U2, …)</code>
where <code>Ui</code> is <code>decay_t<Ai></code> if <code>declval<Ai>()</code> is an rvalue
otherwise <code>Ti</code>.
</li>
</ul>
</cxx-section>
<cxx-section id="meta.logical">
<h1>Logical operator traits</h1>
<p>This subclause describes type traits for applying logical operators to
other type traits.</p>
<pre><code>template<class... B> struct conjunction : <i>see below</i> { };</code></pre>
<p>The class template <code>conjunction</code> forms the logical
conjunction of its template type arguments. Every template type argument
shall be usable as a base class and shall have a static data member
<code>value</code> which is convertible to <code>bool</code>, is not
hidden, and is unambiguously available in the type.</p>
<p>The BaseCharacteristic of a specialization <code>conjunction<B1, …, BN></code>
is the first type <code>B</code> in the list <code>true_type</code>,
<code>B1</code>, …, <code>BN</code> for which <code>B::value == false</code>,
or if every <code>B::value != false</code> the BaseCharacteristic
is the last type in the list. <cxx-note>This means a specialization of <code>conjunction</code>
does not necessarily have a BaseCharacteristic of either <code>true_type</code>
or <code>false_type</code>.</cxx-note></p>
<p>For a specialization <code>conjunction<B1, …, BN></code> if
there is a template type argument <code>B<var>i</var></code> with <code>B<var>i</var>::value == false</code>
then instantiating <code>conjunction<B1, …, BN>::value</code> does
not require the instantiation of <code>B<var>j</var>::value</code> for <code><var>j</var></code> > <code><var>i</var></code>.
<cxx-note>This is analogous to the short-circuiting behavior of <code>&&</code>.</cxx-note></p>
<pre><code>template<class... B> struct disjunction : <i>see below</i> { };</code></pre>
<p>The class template <code>disjunction</code> forms the logical
disjunction of its template type arguments. Every template type argument
shall be usable as a base class and shall have a static data member
<code>value</code> which is convertible to <code>bool</code>, is not
hidden, and is unambiguously available in the type.</p>
<p>The BaseCharacteristic of a specialization <code>disjunction<B1, …, BN></code>
is the first type <code>B</code> in the list <code>false_type</code>,
<code>B1</code>, …, <code>BN</code> for which <code>B::value != false</code>,
or if every <code>B::value == false</code> the BaseCharacteristic
is the last type in the list. <cxx-note>This means a specialization of <code>disjunction</code>
does not necessarily have a BaseCharacteristic of either <code>true_type</code>
or <code>false_type</code>.</cxx-note></p>
<p>For a specialization <code>disjunction<B1, …, BN></code> if
there is a template type argument <code>B<var>i</var></code> with <code>B<var>i</var>::value != false</code>
then instantiating <code>disjunction<B1, …, BN>::value</code> does
not require the instantiation of <code>B<var>j</var>::value</code> for <code><var>j</var></code> > <code><var>i</var></code>.
<cxx-note>This is analogous to the short-circuiting behavior of <code>||</code>.</cxx-note></p>
<pre><code>template<class B> struct negation : integral_constant<bool, !B::value> { };</code></pre>
<p>The class template <code>negation</code> forms the logical negation of
its template type argument. The type <code>negation<B></code> is a
UnaryTypeTrait with a BaseCharacteristic of <code>integral_constant<bool, !B::value></code>.</p>
</cxx-section>
<cxx-section id="meta.detect">
<h1>Detection idiom</h1>
<pre><code>template <class Default, class AlwaysVoid,
template<class...> class Op, class... Args>
struct DETECTOR { // <i>exposition only</i>
using value_t = false_type;
using type = Default;
};
template <class Default, template<class...> class Op, class... Args>
struct DETECTOR<Default, void_t<Op<Args...>>, Op, Args...> { // <i>exposition only</i>
using value_t = true_type;
using type = Op<Args...>;
};
template <template<class...> class Op, class... Args>
using is_detected = typename DETECTOR<nonesuch, void, Op, Args...>::value_t;
template <template<class...> class Op, class... Args>
using detected_t = typename DETECTOR<nonesuch, void, Op, Args...>::type;
template <class Default, template<class...> class Op, class... Args>
using detected_or = DETECTOR<Default, void, Op, Args...>;</code></pre>
<cxx-example>
<pre><code>// <i>archetypal helper alias for a copy assignment operation:</i>
template <class T>
using copy_assign_t = decltype(declval<T&>() = declval<T const &>());
// <i>plausible implementation for the is_assignable type trait:</i>
template <class T>
using is_copy_assignable = is_detected<copy_assign_t, T>;
// <i>plausible implementation for an augmented is_assignable type trait</i>
// <i>that also checks the return type:</i>
template <class T>
using is_canonical_copy_assignable = is_detected_exact<T&, copy_assign_t, T>;</code></pre>
</cxx-example>
<cxx-example>
<pre><code>// <i>archetypal helper alias for a particular type member:</i>
template <class T>
using diff_t = typename T::difference_type;
// <i>alias the type member, if it exists, otherwise alias </i>ptrdiff_t<i>:</i>
template <class Ptr>
using difference_type = detected_or_t<ptrdiff_t, diff_t, Ptr>;</code></pre>
</cxx-example>
</cxx-section>
</cxx-section>
<cxx-section id="ratio">
<h1>Compile-time rational arithmetic</h1>
<cxx-section id="header.ratio.synop">
<h1>Header <experimental/ratio> synopsis</h1>
<pre><code>#include <ratio>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
// See <cxx-ref in="cxx" to="ratio.comparison"></cxx-ref>, ratio comparison
template <class R1, class R2> constexpr bool ratio_equal_v
= ratio_equal<R1, R2>::value;
template <class R1, class R2> constexpr bool ratio_not_equal_v
= ratio_not_equal<R1, R2>::value;
template <class R1, class R2> constexpr bool ratio_less_v
= ratio_less<R1, R2>::value;
template <class R1, class R2> constexpr bool ratio_less_equal_v
= ratio_less_equal<R1, R2>::value;
template <class R1, class R2> constexpr bool ratio_greater_v
= ratio_greater<R1, R2>::value;
template <class R1, class R2> constexpr bool ratio_greater_equal_v
= ratio_greater_equal<R1, R2>::value;
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
</cxx-section>
<cxx-section id="time">
<h1>Time utilities</h1>
<cxx-section id="header.chrono.synop">
<h1>Header <experimental/chrono> synopsis</h1>
<pre><code>#include <chrono>
namespace std {
namespace chrono {
namespace experimental {
inline namespace fundamentals_v2 {
// See <cxx-ref in="cxx" to="time.traits"></cxx-ref>, customization traits
template <class Rep> constexpr bool treat_as_floating_point_v
= treat_as_floating_point<Rep>::value;
} // namespace fundamentals_v2
} // namespace experimental
} // namespace chrono
} // namespace std</code></pre>
</cxx-section>
</cxx-section>
<cxx-section id="syserror">
<h1>System error support</h1>
<cxx-section id="header.system_error.synop">
<h1>Header <experimental/system_error> synopsis</h1>
<pre><code>#include <system_error>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
// See <cxx-ref in="cxx" to="syserr"></cxx-ref>, System error support
template <class T> constexpr bool is_error_code_enum_v
= is_error_code_enum<T>::value;
template <class T> constexpr bool is_error_condition_enum_v
= is_error_condition_enum<T>::value;
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
</cxx-section>
<cxx-section id="propagate_const">
<h1>Class template <code>propagate_const</code></h1>
<cxx-section id="propagate_const.general">
<h1>Class template <code>propagate_const</TT> general</code></h1>
<p>
<code>propagate_const</code> is a wrapper around a pointer-like object type <code>T</code>
which treats the wrapped pointer as a pointer to <code>const</code> when
the wrapper is accessed through a <code>const</code> access path.
</p>
</cxx-section>
<cxx-section id="propagate_const.synopsis">
<h1>Header <code><experimental/propagate_const></code> synopsis</h1>
<pre><code>namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
template <class T> class propagate_const {
public:
typedef remove_reference_t<decltype(*declval<T&>())> element_type;
<cxx-ref insynopsis to="propagate_const.ctor"></cxx-ref>
constexpr propagate_const() = default;
propagate_const(const propagate_const& p) = delete;
constexpr propagate_const(propagate_const&& p) = default;
template <class U>
<i>see below</i> constexpr propagate_const(propagate_const<U>&& pu);
template <class U>
<i>see below</i> constexpr propagate_const(U&& u);
<cxx-ref insynopsis to="propagate_const.assignment"></cxx-ref>
propagate_const& operator=(const propagate_const& p) = delete;
constexpr propagate_const& operator=(propagate_const&& p) = default;
template <class U>
constexpr propagate_const& operator=(propagate_const<U>&& pu);
template <class U>
constexpr propagate_const& operator=(U&& u);
<cxx-ref insynopsis to="propagate_const.const_observers"></cxx-ref>
explicit constexpr operator bool() const;
constexpr const element_type* operator->() const;
constexpr operator const element_type*() const; // <i>Not always defined</i>
constexpr const element_type& operator*() const;
constexpr const element_type* get() const;
<cxx-ref insynopsis to="propagate_const.non_const_observers"></cxx-ref>
constexpr element_type* operator->();
constexpr operator element_type*(); // <i>Not always defined</i>
constexpr element_type& operator*();
constexpr element_type* get();
<cxx-ref insynopsis to="propagate_const.modifiers"></cxx-ref>
constexpr void swap(propagate_const& pt) noexcept(<i>see below</i>);
private:
T t_; //<i>exposition only</i>
};
<cxx-ref insynopsis to="propagate_const.relational"></cxx-ref>
template <class T>
constexpr bool operator==(const propagate_const<T>& pt, nullptr_t);
template <class T>
constexpr bool operator==(nullptr_t, const propagate_const<T>& pu);
template <class T>
constexpr bool operator!=(const propagate_const<T>& pt, nullptr_t);
template <class T>
constexpr bool operator!=(nullptr_t, const propagate_const<T>& pu);
template <class T, class U>
constexpr bool operator==(const propagate_const<T>& pt, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator!=(const propagate_const<T>& pt, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator<(const propagate_const<T>& pt, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator>(const propagate_const<T>& pt, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator<=(const propagate_const<T>& pt, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator>=(const propagate_const<T>& pt, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator==(const propagate_const<T>& pt, const U& u);
template <class T, class U>
constexpr bool operator!=(const propagate_const<T>& pt, const U& u);
template <class T, class U>
constexpr bool operator<(const propagate_const<T>& pt, const U& u);
template <class T, class U>
constexpr bool operator>(const propagate_const<T>& pt, const U& u);
template <class T, class U>
constexpr bool operator<=(const propagate_const<T>& pt, const U& u);
template <class T, class U>
constexpr bool operator>=(const propagate_const<T>& pt, const U& u);
template <class T, class U>
constexpr bool operator==(const T& t, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator!=(const T& t, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator<(const T& t, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator>(const T& t, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator<=(const T& t, const propagate_const<U>& pu);
template <class T, class U>
constexpr bool operator>=(const T& t, const propagate_const<U>& pu);
<cxx-ref insynopsis to="propagate_const.algorithms"></cxx-ref>
template <class T>
constexpr void swap(propagate_const<T>& pt, propagate_const<T>& pt2) noexcept(<i>see below</i>);
<cxx-ref insynopsis to="propagate_const.underlying"></cxx-ref>
template <class T>
constexpr const T& get_underlying(const propagate_const<T>& pt) noexcept;
template <class T>
constexpr T& get_underlying(propagate_const<T>& pt) noexcept;
} // inline namespace fundamentals_v2
} // namespace experimental
<cxx-ref insynopsis to="propagate_const.hash"></cxx-ref>
template <class T> struct hash;
template <class T>
struct hash<experimental::fundamentals_v2::propagate_const<T>>;
<cxx-ref insynopsis to="propagate_const.comparison_function_objects"></cxx-ref>
template <class T> struct equal_to;
template <class T>
struct equal_to<experimental::fundamentals_v2::propagate_const<T>>;
template <class T> struct not_equal_to;
template <class T>
struct not_equal_to<experimental::fundamentals_v2::propagate_const<T>>;
template <class T> struct less;
template <class T>
struct less<experimental::fundamentals_v2::propagate_const<T>>;
template <class T> struct greater;
template <class T>
struct greater<experimental::fundamentals_v2::propagate_const<T>>;
template <class T> struct less_equal;
template <class T>
struct less_equal<experimental::fundamentals_v2::propagate_const<T>>;
template <class T> struct greater_equal;
template <class T>
struct greater_equal<experimental::fundamentals_v2::propagate_const<T>>;
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="propagate_const.requirements">
<h1><code>propagate_const</code> requirements on <code>T</code></h1>
<p>
<code>T</code> shall be an object pointer type or a class type for which
<code>decltype(*declval<T&>())</code> is an lvalue reference; otherwise
the program is ill-formed.
</p>
<p>
If <code>T</code> is an array type, reference type, pointer to function type or
pointer to (possibly cv-qualified) <code>void</code>, then the program is
ill-formed.
</p>
<p>
<cxx-note><code>propagate_const<const int*></code> is well-formed</cxx-note>
</p>
<cxx-section id="propagate_const.class_type_requirements">
<h1><code>propagate_const</code> requirements on class type <code>T</code></h1>
<p>
If <code>T</code> is class
type then it shall satisfy the following requirements. In this sub-clause
<code>t</code> denotes a non-<code>const</code> lvalue of type <code>T</code>, <code>ct</code>
is a <code>const T&</code> bound to <code>t</code>, <code>element_type</code> denotes
an object type.
</p>
<p>
<code>T</code> and <code>const T</code> shall be contextually convertible to <code>bool</code>.
</p>
<p>If <code>T</code> is implicitly convertible to <code>element_type*</code>,
<code>(element_type*)t == t.get()</code> shall be <code>true</code>.
</p>
<p>
If <code>const T</code> is implicitly convertible to <code>const element_type*</code>,
<code>(const element_type*)ct == ct.get()</code> shall be <code>true</code>.
</p>
<table is="cxx-table">
<caption>Requirements on class types <code>T</code></caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Pre-conditions</th>
<th>Operational semantics</th>
</tr>
<tr>
<td><code>t.get()</code></td>
<td><code>element_type*</code></td>
<td></td>
<td></td>
</tr>
<tr>
<td><code>ct.get()</code></td>
<td><code>const element_type*</code> or <code>element_type*</code></td>
<td><code></code></td>
<td><code>t.get() == ct.get()</code>.</td>
</tr>
<tr>
<td><code>*t</code></td>
<td><code>element_type&</code></td>
<td><code>t.get() != nullptr</code></td>
<td><code>*t</code> refers to the same object as <code>*(t.get())</code></td>
</tr>
<tr>
<td><code>*ct</code></td>
<td><code>const element_type&</code> or <code>element_type&</code>
</td>
<td><code>ct.get() != nullptr</code></td>
<td><code>*ct</code> refers to the same object as <code>*(ct.get())</code>
</td></tr>
<tr>
<td><code>t.operator->()</code></td>
<td><code>element_type*</code></td>
<td><code>t.get() != nullptr</code></td>
<td><code>t.operator->() == t.get()</code></td></tr>
<tr>
<td><code>ct.operator->()</code></td>
<td><code>const element_type*</code> or <code>element_type*</code></td>
<td><code>ct.get() != nullptr</code></td>
<td><code>ct.operator->() == ct.get()</code></td></tr>
<tr>
<td><code>(bool)t</code></td>
<td><code>bool</code></td>
<td><code></code></td>
<td><code>(bool)t</code> is equivalent to <code>t.get() != nullptr</code></td>
</tr>
<tr>
<td><code>(bool)ct</code></td>
<td><code>bool</code></td>
<td><code></code></td>
<td><code>(bool)ct</code> is equivalent to <code>ct.get() != nullptr</code></td>
</tr>
</table>
</cxx-section>
</cxx-section>
<cxx-section id="propagate_const.ctor">
<h1><code>propagate_const</code> constructors</h1>
<p>
<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>
</p>
<cxx-function>
<cxx-signature>template <class U>
<i>see below</i> constexpr propagate_const(propagate_const<U>&& pu);</cxx-signature>
<cxx-remarks>
This constructor shall not participate in overload resolution unless
<code>is_constructible_v<T, U&&></code>.
The constructor is specified as <code>explicit</code> if and only if
<code>!is_convertible_v<U&&, T>.</code>
</cxx-remarks>
<cxx-effects>
Initializes <code>t_</code> as if
direct-non-list-initializing an object of type <code>T</code> with the
expression <code>std::move(pu.t_)</code>.
</cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U>
<i>see below</i> constexpr propagate_const(U&& u);</cxx-signature>
<cxx-remarks>
This constructor shall not participate in overload resolution unless
<code>is_constructible_v<T, U&&></code>
and <code>decay_t<U></code> is not a specialization of <code>propagate_const</code>.
The constructor is specified as <code>explicit</code> if and only if
<code>!is_convertible_v<U&&, T>.</code>
</cxx-remarks>
<cxx-effects>
Initializes <code>t_</code> as if
direct-non-list-initializing an object of type <code>T</code> with
the expression <code>std::forward<U>(u)</code>.
</cxx-effects>
</cxx-function>
</cxx-section>
<cxx-section id="propagate_const.assignment">
<h1><code>propagate_const</code> assignment</h1>
<cxx-function>
<cxx-signature>template <class U>
constexpr propagate_const& operator=(propagate_const<U>&& pu);</cxx-signature>
<cxx-remarks>
This function shall not participate in overload resolution unless
<code>U</code> is implicitly convertible to <code>T</code>.
</cxx-remarks>
<cxx-effects><code>t_ = std::move(pu.t_)</code>.</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template <class U>
constexpr propagate_const& operator=(U&& u);</cxx-signature>
<cxx-remarks>
This function shall not participate in overload resolution unless
<code>U</code> is implicitly convertible to <code>T</code> and
<code>decay_t<U></code> is not a specialization of <code>propagate_const</code>.
</cxx-remarks>
<cxx-effects><code>t_ = std::forward<U>(u)</code>.</cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="propagate_const.const_observers">
<h1><code>propagate_const</code> const observers</h1>
<cxx-function>
<cxx-signature>explicit constexpr operator bool() const;</cxx-signature>
<cxx-returns><code>(bool)t_</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const element_type* operator->() const;</cxx-signature>
<cxx-requires><code>get() != nullptr</code>.</cxx-requires>
<cxx-returns><code>get()</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr operator const element_type*() const;</cxx-signature>
<cxx-returns><code>get()</code>.</cxx-returns>
<cxx-remarks>
This function shall not participate in overload resolution unless
<code>T</code> is an object pointer type or
has an implicit conversion to <code>const element_type*</code>.
</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const element_type& operator*() const;</cxx-signature>
<cxx-requires><code>get() != nullptr</code>.</cxx-requires>
<cxx-returns><code>*get()</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const element_type* get() const;</cxx-signature>
<cxx-returns>
<code>t_</code> if <code>T</code> is an object pointer type,
otherwise <code>t_.get()</code>.
</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="propagate_const.non_const_observers">
<h1><code>propagate_const</code> non-const observers</h1>
<cxx-function>
<cxx-signature>constexpr element_type* operator->();</cxx-signature>
<cxx-requires><code>get() != nullptr</code>.</cxx-requires>
<cxx-returns><code>get()</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr operator element_type*();</cxx-signature>
<cxx-returns><code>get()</code>.</cxx-returns>