-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
variant
1772 lines (1554 loc) · 82.7 KB
/
variant
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
// variant standard header
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#pragma once
#ifndef _VARIANT_
#define _VARIANT_
#include <yvals.h>
#if _STL_COMPILER_PREPROCESSOR
#if !_HAS_CXX17
#pragma message("The contents of <variant> are available only with C++17 or later.")
#else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv
#include <exception>
#include <initializer_list>
#include <type_traits>
#include <utility>
#include <xmemory>
#include <xsmf_control.h>
#include <xstddef>
#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
#ifdef __clang__
#define _STL_UNREACHABLE __builtin_unreachable()
#else // ^^^ clang ^^^ / vvv other vvv
#define _STL_UNREACHABLE __assume(false)
#endif // __clang__
_STD_BEGIN
template <class...>
struct _All_same : true_type {};
template <class _First, class... _Rest>
struct _All_same<_First, _Rest...> : bool_constant<conjunction_v<is_same<_First, _Rest>...>> {}; // variadic is_same
template <class _To, class... _From>
struct _Convertible_from_all : bool_constant<conjunction_v<is_convertible<_From, _To>...>> {
// variadic is_convertible
};
template <class...>
struct _Meta_list {}; // a sequence of types
struct _Meta_nil {};
template <class _List>
struct _Meta_front_;
template <class _List>
using _Meta_front =
// extract the first type in a sequence (head of list)
typename _Meta_front_<_List>::type;
template <template <class...> class _List, class _First, class... _Rest>
struct _Meta_front_<_List<_First, _Rest...>> {
using type = _First;
};
template <class _List>
struct _Meta_pop_front_;
template <class _List>
using _Meta_pop_front =
// subsequence including all but the first type (tail of list)
typename _Meta_pop_front_<_List>::type;
template <template <class...> class _List, class _First, class... _Rest>
struct _Meta_pop_front_<_List<_First, _Rest...>> {
using type = _List<_Rest...>;
};
template <class _List, class _Ty>
struct _Meta_push_front_;
template <class _List, class _Ty>
using _Meta_push_front =
// prepend a new type onto a sequence
typename _Meta_push_front_<_List, _Ty>::type;
template <template <class...> class _List, class... _Types, class _Ty>
struct _Meta_push_front_<_List<_Types...>, _Ty> {
using type = _List<_Ty, _Types...>;
};
template <class _Void, template <class...> class _Fn, class... _Args>
struct _Meta_quote_helper_;
template <template <class...> class _Fn, class... _Args>
struct _Meta_quote_helper_<void_t<_Fn<_Args...>>, _Fn, _Args...> {
using type = _Fn<_Args...>;
};
template <template <class...> class _Fn>
struct _Meta_quote { // encapsulate a template into a meta-callable type
template <class... _Types>
using _Invoke = typename _Meta_quote_helper_<void, _Fn, _Types...>::type;
};
template <class _Fn, class... _Args>
using _Meta_invoke = // invoke meta-callable _Fn with _Args
typename _Fn::template _Invoke<_Args...>;
template <class _Fn, class... _Args>
struct _Meta_bind_back { // construct a meta-callable that passes its arguments and _Args to _Fn
template <class... _Types>
using _Invoke = _Meta_invoke<_Fn, _Types..., _Args...>;
};
template <class _Fn, class _List>
struct _Meta_apply_;
template <class _Fn, class _List>
using _Meta_apply =
// explode _List into the parameters of meta-callable _Fn
typename _Meta_apply_<_Fn, _List>::type;
template <class _Fn, template <class...> class _List, class... _Types>
struct _Meta_apply_<_Fn,
_List<_Types...>> { // invoke meta-callable _Fn with the parameters of a template specialization
using type = _Meta_invoke<_Fn, _Types...>;
};
template <class _Fn, class _Ty, _Ty... _Idxs>
struct _Meta_apply_<_Fn,
integer_sequence<_Ty, _Idxs...>> { // invoke meta-callable _Fn with the elements of an integer_sequence
using type = _Meta_invoke<_Fn, integral_constant<_Ty, _Idxs>...>;
};
template <class _Fn, class _List>
struct _Meta_transform_;
template <class _Fn, class _List>
using _Meta_transform =
// transform sequence of _Types... into sequence of _Fn<_Types...>
typename _Meta_transform_<_Fn, _List>::type;
template <template <class...> class _List, class _Fn, class... _Types>
struct _Meta_transform_<_Fn, _List<_Types...>> {
using type = _List<_Meta_invoke<_Fn, _Types>...>;
};
template <class, class, template <class...> class>
struct _Meta_repeat_n_c_;
template <size_t _Count, class _Ty, template <class...> class _Continue>
using _Meta_repeat_n_c =
// construct a sequence consisting of repetitions of _Ty
typename _Meta_repeat_n_c_<_Ty, make_index_sequence<_Count>, _Continue>::type;
template <class _Ty, size_t>
using _Meta_repeat_first_helper = _Ty;
template <class _Ty, size_t... _Idxs, template <class...> class _Continue>
struct _Meta_repeat_n_c_<_Ty, index_sequence<_Idxs...>, _Continue> {
using type = _Continue<_Meta_repeat_first_helper<_Ty, _Idxs>...>;
};
template <class _List, size_t _Idx, class = void>
struct _Meta_at_;
template <class _List, size_t _Idx>
using _Meta_at_c =
// Extract the _Idx-th type from _List
typename _Meta_at_<_List, _Idx>::type;
#ifdef __clang__
template <template <class...> class _List, class... _Types, size_t _Idx>
struct _Meta_at_<_List<_Types...>, _Idx, void_t<__type_pack_element<_Idx, _Types...>>> {
using type = __type_pack_element<_Idx, _Types...>;
};
#else // ^^^ __clang__ / !__clang__ vvv
template <class... _VoidPtrs>
struct _Meta_at_impl {
template <class _Ty, class... _Types>
static _Ty _Eval(_VoidPtrs..., _Ty*, _Types*...); // undefined
};
template <class _Ty>
constexpr _Identity<_Ty>* _Type_as_pointer() {
return nullptr;
}
template <template <class...> class _List, class... _Types, size_t _Idx>
struct _Meta_at_<_List<_Types...>, _Idx, enable_if_t<(_Idx < sizeof...(_Types))>> {
using type =
typename decltype(_Meta_repeat_n_c<_Idx, void*, _Meta_at_impl>::_Eval(_Type_as_pointer<_Types>()...))::type;
};
#endif // __clang__
inline constexpr auto _Meta_npos = ~size_t{0};
template <class _List, class _Ty>
struct _Meta_find_index_ {
using type = integral_constant<size_t, _Meta_npos>;
};
template <class _List, class _Ty>
using _Meta_find_index =
// find the index of the first occurrence of _Ty in _List
typename _Meta_find_index_<_List, _Ty>::type;
constexpr size_t _Meta_find_index_i_(const bool* const _Ptr, const size_t _Count,
size_t _Idx = 0) { // return the index of the first true in the _Count bools at _Ptr, or _Meta_npos if all are false
for (; _Idx < _Count; ++_Idx) {
if (_Ptr[_Idx]) {
return _Idx;
}
}
return _Meta_npos;
}
template <template <class...> class _List, class _First, class... _Rest, class _Ty>
struct _Meta_find_index_<_List<_First, _Rest...>, _Ty> {
static constexpr bool _Bools[] = {is_same_v<_First, _Ty>, is_same_v<_Rest, _Ty>...};
using type = integral_constant<size_t, _Meta_find_index_i_(_Bools, 1 + sizeof...(_Rest))>;
};
template <class _List, class _Ty>
struct _Meta_find_unique_index_ {
using type = integral_constant<size_t, _Meta_npos>;
};
template <class _List, class _Ty>
using _Meta_find_unique_index =
// The index of _Ty in _List if it occurs exactly once, otherwise _Meta_npos
typename _Meta_find_unique_index_<_List, _Ty>::type;
constexpr size_t _Meta_find_unique_index_i_2(const bool* const _Ptr, const size_t _Count,
const size_t
_First) { // return _First if there is no _First < j < _Count such that _Ptr[j] is true, otherwise _Meta_npos
return _First != _Meta_npos && _Meta_find_index_i_(_Ptr, _Count, _First + 1) == _Meta_npos ? _First : _Meta_npos;
}
constexpr size_t _Meta_find_unique_index_i_(const bool* const _Ptr,
const size_t _Count) { // Pass the smallest i such that _Ptr[i] is true to _Meta_find_unique_index_i_2
return _Meta_find_unique_index_i_2(_Ptr, _Count, _Meta_find_index_i_(_Ptr, _Count));
}
template <template <class...> class _List, class _First, class... _Rest, class _Ty>
struct _Meta_find_unique_index_<_List<_First, _Rest...>, _Ty> {
using type = integral_constant<size_t,
_Meta_find_unique_index_i_(_Meta_find_index_<_List<_First, _Rest...>, _Ty>::_Bools, 1 + sizeof...(_Rest))>;
};
template <class>
struct _Meta_as_list_;
template <class _Ty>
using _Meta_as_list =
// convert _Ty to a _Meta_list
typename _Meta_as_list_<_Ty>::type;
template <template <class...> class _List, class... _Types>
struct _Meta_as_list_<_List<_Types...>> { // convert the parameters of an arbitrary template specialization to a
// _Meta_list of types
using type = _Meta_list<_Types...>;
};
template <class _Ty, _Ty... _Idxs>
struct _Meta_as_list_<integer_sequence<_Ty, _Idxs...>> { // convert an integer_sequence to a _Meta_list of
// integral_constants
using type = _Meta_list<integral_constant<_Ty, _Idxs>...>;
};
template <class _List>
struct _Meta_as_integer_sequence_;
template <class _List>
using _Meta_as_integer_sequence =
// convert a list of integral_constants to an integer_sequence
typename _Meta_as_integer_sequence_<_List>::type;
template <template <class...> class _List, class _Ty, _Ty... _Idxs>
struct _Meta_as_integer_sequence_<_List<integral_constant<_Ty, _Idxs>...>> {
using type = integer_sequence<_Ty, _Idxs...>;
};
template <class...>
struct _Meta_concat_;
template <class... _Types>
using _Meta_concat =
// merge several lists into one
typename _Meta_concat_<_Types...>::type;
template <template <class...> class _List>
struct _Meta_concat_<_List<>> {
using type = _List<>;
};
template <template <class...> class _List, class... _Items1>
struct _Meta_concat_<_List<_Items1...>> {
using type = _List<_Items1...>;
};
template <template <class...> class _List, class... _Items1, class... _Items2>
struct _Meta_concat_<_List<_Items1...>, _List<_Items2...>> {
using type = _List<_Items1..., _Items2...>;
};
template <template <class...> class _List, class... _Items1, class... _Items2, class... _Items3>
struct _Meta_concat_<_List<_Items1...>, _List<_Items2...>, _List<_Items3...>> {
using type = _List<_Items1..., _Items2..., _Items3...>;
};
template <template <class...> class _List, class... _Items1, class... _Items2, class... _Items3, class... _Rest>
struct _Meta_concat_<_List<_Items1...>, _List<_Items2...>, _List<_Items3...>, _Rest...> {
using type = _Meta_concat<_List<_Items1..., _Items2..., _Items3...>, _Rest...>;
};
template <class _ListOfLists>
using _Meta_join =
// transform a list of lists of elements into a single list containing those elements
_Meta_apply<_Meta_quote<_Meta_concat>, _ListOfLists>;
template <class>
struct _Meta_cartesian_product_;
template <class _ListOfLists>
using _Meta_cartesian_product =
// find the n-ary Cartesian Product of the lists in the input list
typename _Meta_cartesian_product_<_ListOfLists>::type;
template <template <class...> class _List>
struct _Meta_cartesian_product_<_List<>> {
using type = _List<>;
};
template <template <class...> class _List1, template <class...> class _List2, class... _Items>
struct _Meta_cartesian_product_<_List1<_List2<_Items...>>> {
using type = _List1<_List2<_Items>...>;
};
template <template <class...> class _List1, class... _Items, template <class...> class _List2, class... _Lists>
struct _Meta_cartesian_product_<_List1<_List2<_Items...>, _Lists...>> {
using type = _Meta_join<_List1<_Meta_transform<_Meta_bind_back<_Meta_quote<_Meta_push_front>, _Items>,
_Meta_cartesian_product<_List1<_Lists...>>>...>>;
};
#define _STL_STAMP4(n, x) \
x(n); \
x(n + 1); \
x(n + 2); \
x(n + 3)
#define _STL_STAMP16(n, x) \
_STL_STAMP4(n, x); \
_STL_STAMP4(n + 4, x); \
_STL_STAMP4(n + 8, x); \
_STL_STAMP4(n + 12, x)
#define _STL_STAMP64(n, x) \
_STL_STAMP16(n, x); \
_STL_STAMP16(n + 16, x); \
_STL_STAMP16(n + 32, x); \
_STL_STAMP16(n + 48, x)
#define _STL_STAMP256(n, x) \
_STL_STAMP64(n, x); \
_STL_STAMP64(n + 64, x); \
_STL_STAMP64(n + 128, x); \
_STL_STAMP64(n + 192, x)
#define _STL_STAMP(n, x) x(_STL_STAMP##n, n)
template <class... _Types>
class variant;
template <class _Ty>
struct variant_size; // undefined
template <class _Ty>
struct variant_size<const _Ty> : variant_size<_Ty>::type {};
template <class _Ty>
struct _CXX20_DEPRECATE_VOLATILE variant_size<volatile _Ty> : variant_size<_Ty>::type {};
template <class _Ty>
struct _CXX20_DEPRECATE_VOLATILE variant_size<const volatile _Ty> : variant_size<_Ty>::type {};
template <class _Ty>
inline constexpr size_t variant_size_v = variant_size<_Ty>::value;
template <class... _Types>
struct variant_size<variant<_Types...>> : integral_constant<size_t, sizeof...(_Types)> {};
template <size_t _Idx, class _Ty>
struct variant_alternative; // undefined
template <size_t _Idx, class _Ty>
using variant_alternative_t = typename variant_alternative<_Idx, _Ty>::type;
template <size_t _Idx, class _Ty>
struct variant_alternative<_Idx, const _Ty> {
using type = add_const_t<variant_alternative_t<_Idx, _Ty>>;
};
template <size_t _Idx, class _Ty>
struct _CXX20_DEPRECATE_VOLATILE variant_alternative<_Idx, volatile _Ty> {
using type = add_volatile_t<variant_alternative_t<_Idx, _Ty>>;
};
template <size_t _Idx, class _Ty>
struct _CXX20_DEPRECATE_VOLATILE variant_alternative<_Idx, const volatile _Ty> {
using type = add_cv_t<variant_alternative_t<_Idx, _Ty>>;
};
template <size_t _Idx, class... _Types>
struct variant_alternative<_Idx, variant<_Types...>> {
static_assert(_Idx < sizeof...(_Types), "variant index out of bounds");
#ifdef __clang__
using type = __type_pack_element<_Idx, _Types...>;
#else // ^^^ __clang__ ^^^ / vvv !__clang__ vvv
using type = _Meta_at_c<variant<_Types...>, _Idx>;
#endif // __clang__
};
inline constexpr size_t variant_npos = _Meta_npos;
class bad_variant_access
: public exception { // exception for visit of a valueless variant or get<I> on a variant with index() != I
public:
bad_variant_access() noexcept = default;
_NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override {
return "bad variant access";
}
#if !_HAS_EXCEPTIONS
protected:
void _Doraise() const override { // perform class-specific exception handling
_RAISE(*this);
}
#endif // !_HAS_EXCEPTIONS
};
[[noreturn]] inline void _Throw_bad_variant_access() {
_THROW(bad_variant_access{});
}
template <bool _TrivialDestruction, class... _Types>
class _Variant_storage_ {}; // empty storage (empty "_Types" case)
template <class... _Types>
using _Variant_storage = _Variant_storage_<conjunction_v<is_trivially_destructible<_Types>...>, _Types...>;
template <class _First, class... _Rest>
class _Variant_storage_<true, _First, _Rest...> { // Storage for variant alternatives (trivially destructible case)
public:
static constexpr size_t _Size = 1 + sizeof...(_Rest);
union {
remove_const_t<_First> _Head;
_Variant_storage<_Rest...> _Tail;
};
_CONSTEXPR20 _Variant_storage_() noexcept {} // no initialization (no active member)
template <class... _Types>
constexpr explicit _Variant_storage_(integral_constant<size_t, 0>, _Types&&... _Args) noexcept(
is_nothrow_constructible_v<_First, _Types...>)
: _Head(static_cast<_Types&&>(_Args)...) {} // initialize _Head with _Args...
template <size_t _Idx, class... _Types, enable_if_t<(_Idx > 0), int> = 0>
constexpr explicit _Variant_storage_(integral_constant<size_t, _Idx>, _Types&&... _Args) noexcept(
is_nothrow_constructible_v<_Variant_storage<_Rest...>, integral_constant<size_t, _Idx - 1>, _Types...>)
: _Tail(integral_constant<size_t, _Idx - 1>{}, static_cast<_Types&&>(_Args)...) {} // initialize _Tail (recurse)
_NODISCARD constexpr _First& _Get() & noexcept {
return _Head;
}
_NODISCARD constexpr const _First& _Get() const& noexcept {
return _Head;
}
_NODISCARD constexpr _First&& _Get() && noexcept {
return _STD move(_Head);
}
_NODISCARD constexpr const _First&& _Get() const&& noexcept {
return _STD move(_Head);
}
};
template <class _First, class... _Rest>
class _Variant_storage_<false, _First, _Rest...> { // Storage for variant alternatives (non-trivially destructible case)
public:
static constexpr size_t _Size = 1 + sizeof...(_Rest);
union {
remove_const_t<_First> _Head;
_Variant_storage<_Rest...> _Tail;
};
_CONSTEXPR20 ~_Variant_storage_() noexcept {
// explicitly non-trivial destructor (which would otherwise be defined as deleted
// since the class has a variant member with a non-trivial destructor)
}
_CONSTEXPR20 _Variant_storage_() noexcept {} // no initialization (no active member)
template <class... _Types>
constexpr explicit _Variant_storage_(integral_constant<size_t, 0>, _Types&&... _Args) noexcept(
is_nothrow_constructible_v<_First, _Types...>)
: _Head(static_cast<_Types&&>(_Args)...) {} // initialize _Head with _Args...
template <size_t _Idx, class... _Types, enable_if_t<(_Idx > 0), int> = 0>
constexpr explicit _Variant_storage_(integral_constant<size_t, _Idx>, _Types&&... _Args) noexcept(
is_nothrow_constructible_v<_Variant_storage<_Rest...>, integral_constant<size_t, _Idx - 1>, _Types...>)
: _Tail(integral_constant<size_t, _Idx - 1>{}, static_cast<_Types&&>(_Args)...) {} // initialize _Tail (recurse)
_Variant_storage_(_Variant_storage_&&) = default;
_Variant_storage_(const _Variant_storage_&) = default;
_Variant_storage_& operator=(_Variant_storage_&&) = default;
_Variant_storage_& operator=(const _Variant_storage_&) = default;
_NODISCARD constexpr _First& _Get() & noexcept {
return _Head;
}
_NODISCARD constexpr const _First& _Get() const& noexcept {
return _Head;
}
_NODISCARD constexpr _First&& _Get() && noexcept {
return _STD move(_Head);
}
_NODISCARD constexpr const _First&& _Get() const&& noexcept {
return _STD move(_Head);
}
};
#ifdef __cplusplus_winrt // TRANSITION, VSO-586813
// C++/CX is unable to store hats in unions. We instead store them inside a
// wrapper to enable minimal hats-in-variants support.
template <class _Ty>
struct _Variant_item {
remove_const_t<_Ty> _Item;
template <class... _Types>
constexpr _Variant_item(_Types&&... _Args) noexcept(is_nothrow_constructible_v<_Ty, _Types...>)
: _Item(static_cast<_Types&&>(_Args)...) {}
};
template <class _First, class... _Rest>
class _Variant_storage_<false, _First ^, _Rest...> { // Storage for variant alternatives (^ case)
public:
static constexpr size_t _Size = 1 + sizeof...(_Rest);
union {
_Variant_item<_First ^> _Head;
_Variant_storage<_Rest...> _Tail;
};
_CONSTEXPR20 ~_Variant_storage_() noexcept {
// explicitly non-trivial destructor (which would otherwise be defined as deleted
// since the class has a variant member with a non-trivial destructor)
}
_CONSTEXPR20 _Variant_storage_() noexcept {} // no initialization (no active member)
template <class... _Types>
constexpr explicit _Variant_storage_(integral_constant<size_t, 0>, _Types&&... _Args) noexcept(
is_nothrow_constructible_v<_First ^, _Types...>)
: _Head(static_cast<_Types&&>(_Args)...) {} // initialize _Head with _Args...
template <size_t _Idx, class... _Types, enable_if_t<(_Idx > 0), int> = 0>
constexpr explicit _Variant_storage_(integral_constant<size_t, _Idx>, _Types&&... _Args) noexcept(
is_nothrow_constructible_v<_Variant_storage<_Rest...>, integral_constant<size_t, _Idx - 1>, _Types...>)
: _Tail(integral_constant<size_t, _Idx - 1>{}, static_cast<_Types&&>(_Args)...) {} // initialize _Tail (recurse)
_Variant_storage_(_Variant_storage_&&) = default;
_Variant_storage_(const _Variant_storage_&) = default;
_Variant_storage_& operator=(_Variant_storage_&&) = default;
_Variant_storage_& operator=(const _Variant_storage_&) = default;
_NODISCARD constexpr _First ^ &_Get() & noexcept {
return _Head._Item;
}
_NODISCARD constexpr _First ^ const& _Get() const& noexcept {
return _Head._Item;
}
_NODISCARD constexpr _First ^ &&_Get() && noexcept {
return _STD move(_Head)._Item;
}
_NODISCARD constexpr _First ^ const&& _Get() const&& noexcept {
return _STD move(_Head)._Item;
}
};
#endif // __cplusplus_winrt
template <size_t _Idx, class _Storage>
_NODISCARD constexpr decltype(auto) _Variant_raw_get(
_Storage&& _Obj) noexcept { // access the _Idx-th element of a _Variant_storage
if constexpr (_Idx == 0) {
return static_cast<_Storage&&>(_Obj)._Get();
} else if constexpr (_Idx == 1) {
return static_cast<_Storage&&>(_Obj)._Tail._Get();
} else if constexpr (_Idx == 2) {
return static_cast<_Storage&&>(_Obj)._Tail._Tail._Get();
} else if constexpr (_Idx == 3) {
return static_cast<_Storage&&>(_Obj)._Tail._Tail._Tail._Get();
} else if constexpr (_Idx == 4) {
return static_cast<_Storage&&>(_Obj)._Tail._Tail._Tail._Tail._Get();
} else if constexpr (_Idx == 5) {
return static_cast<_Storage&&>(_Obj)._Tail._Tail._Tail._Tail._Tail._Get();
} else if constexpr (_Idx == 6) {
return static_cast<_Storage&&>(_Obj)._Tail._Tail._Tail._Tail._Tail._Tail._Get();
} else if constexpr (_Idx == 7) {
return static_cast<_Storage&&>(_Obj)._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Get();
} else if constexpr (_Idx < 16) {
return _Variant_raw_get<_Idx - 8>(
static_cast<_Storage&&>(_Obj)._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail);
} else if constexpr (_Idx < 32) {
return _Variant_raw_get<_Idx - 16>(
static_cast<_Storage&&>(_Obj)
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail);
} else if constexpr (_Idx < 64) {
return _Variant_raw_get<_Idx - 32>(
static_cast<_Storage&&>(_Obj)
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail);
} else { // _Idx >= 64
return _Variant_raw_get<_Idx - 64>(
static_cast<_Storage&&>(_Obj)
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail
._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail._Tail);
}
}
template <class _Ty, size_t _Tag>
struct _Tagged { // aggregate a runtime value and a compile-time tag value
static constexpr size_t _Idx = _Tag;
_Ty _Val;
};
template <class _Storage, size_t _Idx>
using _Variant_tagged_ref_t = _Tagged<decltype(_Variant_raw_get<_Idx>(_STD declval<_Storage>()))&&, _Idx>;
template <class _Fn, class _Storage>
using _Variant_raw_visit_t = decltype(_STD declval<_Fn>()(_STD declval<_Variant_tagged_ref_t<_Storage, 0>>()));
template <size_t _Idx, class _Fn, class _Storage>
_NODISCARD constexpr _Variant_raw_visit_t<_Fn, _Storage> _Variant_raw_visit_dispatch(
_Fn&& _Func, _Storage&& _Var) noexcept(is_nothrow_invocable_v<_Fn, _Variant_tagged_ref_t<_Storage, _Idx>>) {
// call _Func with the _Idx-th element in _Storage (tagged with _Idx)
return static_cast<_Fn&&>(_Func)(
_Variant_tagged_ref_t<_Storage, _Idx>{_Variant_raw_get<_Idx>(static_cast<_Storage&&>(_Var))});
}
template <class _Fn, class _Storage>
_NODISCARD constexpr _Variant_raw_visit_t<_Fn, _Storage> _Variant_raw_visit_valueless(
_Fn&& _Func, _Storage&& _Obj) noexcept(is_nothrow_invocable_v<_Fn, _Tagged<_Storage&&, variant_npos>>) {
// call _Func with _Storage (tagged with variant_npos)
return static_cast<_Fn&&>(_Func)(_Tagged<_Storage&&, variant_npos>{static_cast<_Storage&&>(_Obj)});
}
template <class _Fn, class _Storage, class _Indices = make_index_sequence<remove_reference_t<_Storage>::_Size>>
inline constexpr bool _Variant_raw_visit_noexcept = false;
template <class _Fn, class _Storage, size_t... _Idxs>
inline constexpr bool _Variant_raw_visit_noexcept<_Fn, _Storage, index_sequence<_Idxs...>> =
conjunction_v<is_nothrow_invocable<_Fn, _Tagged<_Storage&&, variant_npos>>,
is_nothrow_invocable<_Fn, _Variant_tagged_ref_t<_Storage, _Idxs>>...>;
template <class _Fn, class _Storage,
class _Indices = make_index_sequence<remove_reference_t<_Storage>::_Size>>
struct _Variant_raw_dispatch_table1; // undefined
template <class _Fn, class _Storage, size_t... _Idxs>
struct _Variant_raw_dispatch_table1<_Fn, _Storage,
index_sequence<_Idxs...>> { // map from canonical index to visitation target
using _Dispatch_t = _Variant_raw_visit_t<_Fn, _Storage> (*)(_Fn&&, _Storage&&) noexcept(
_Variant_raw_visit_noexcept<_Fn, _Storage>);
static constexpr _Dispatch_t _Array[] = {
&_Variant_raw_visit_valueless<_Fn, _Storage>, &_Variant_raw_visit_dispatch<_Idxs, _Fn, _Storage>...};
};
template <int _Strategy>
struct _Variant_raw_visit1;
template <>
struct _Variant_raw_visit1<-1> { // Fallback case for variants too large for any of the following "switch" strategies
template <class _Fn, class _Storage>
_NODISCARD static constexpr _Variant_raw_visit_t<_Fn, _Storage> _Visit(
size_t _Idx, _Fn&& _Func, _Storage&& _Obj) noexcept(_Variant_raw_visit_noexcept<_Fn, _Storage>) {
// dispatch a visitor for a _Variant_storage with many states
constexpr size_t _Size = remove_reference_t<_Storage>::_Size;
static_assert(_Size > 256);
constexpr auto& _Array = _Variant_raw_dispatch_table1<_Fn, _Storage>::_Array;
return _Array[_Idx](static_cast<_Fn&&>(_Func), static_cast<_Storage&&>(_Obj));
}
};
#define _STL_CASE(n) \
case (n) + 1: \
if constexpr ((n) < _Size) { \
return static_cast<_Fn&&>(_Func)( \
_Variant_tagged_ref_t<_Storage, (n)>{_Variant_raw_get<(n)>(static_cast<_Storage&&>(_Obj))}); \
} \
_STL_UNREACHABLE
#define _STL_VISIT_STAMP(stamper, n) \
constexpr size_t _Size = remove_reference_t<_Storage>::_Size; \
static_assert(((n) == 4 || _Size > (n) / 4) && _Size <= (n)); \
switch (_Idx) { \
case 0: \
return static_cast<_Fn&&>(_Func)(_Tagged<_Storage&&, variant_npos>{static_cast<_Storage&&>(_Obj)}); \
\
stamper(0, _STL_CASE); \
default: \
_STL_UNREACHABLE; \
}
template <>
struct _Variant_raw_visit1<1> {
template <class _Fn, class _Storage>
_NODISCARD static constexpr _Variant_raw_visit_t<_Fn, _Storage> _Visit(
size_t _Idx, _Fn&& _Func, _Storage&& _Obj) noexcept(_Variant_raw_visit_noexcept<_Fn, _Storage>) {
// dispatch a visitor for a _Variant_storage with at most 4^1 states
_STL_STAMP(4, _STL_VISIT_STAMP);
}
};
template <>
struct _Variant_raw_visit1<2> {
template <class _Fn, class _Storage>
_NODISCARD static constexpr _Variant_raw_visit_t<_Fn, _Storage> _Visit(
size_t _Idx, _Fn&& _Func, _Storage&& _Obj) noexcept(_Variant_raw_visit_noexcept<_Fn, _Storage>) {
// dispatch a visitor for a _Variant_storage with at most 4^2 states
_STL_STAMP(16, _STL_VISIT_STAMP);
}
};
template <>
struct _Variant_raw_visit1<3> {
template <class _Fn, class _Storage>
_NODISCARD static constexpr _Variant_raw_visit_t<_Fn, _Storage> _Visit(
size_t _Idx, _Fn&& _Func, _Storage&& _Obj) noexcept(_Variant_raw_visit_noexcept<_Fn, _Storage>) {
// dispatch a visitor for a _Variant_storage with at most 4^3 states
_STL_STAMP(64, _STL_VISIT_STAMP);
}
};
template <>
struct _Variant_raw_visit1<4> {
template <class _Fn, class _Storage>
_NODISCARD static constexpr _Variant_raw_visit_t<_Fn, _Storage> _Visit(
size_t _Idx, _Fn&& _Func, _Storage&& _Obj) noexcept(_Variant_raw_visit_noexcept<_Fn, _Storage>) {
// dispatch a visitor for a _Variant_storage with at most 4^4 states
_STL_STAMP(256, _STL_VISIT_STAMP);
}
};
#undef _STL_VISIT_STAMP
#undef _STL_CASE
template <class _Storage, class _Fn>
_NODISCARD constexpr _Variant_raw_visit_t<_Fn, _Storage> _Variant_raw_visit(
size_t _Idx, _Storage&& _Obj, _Fn&& _Func) noexcept(_Variant_raw_visit_noexcept<_Fn, _Storage>) {
// Call _Func with _Storage if _Idx is variant_npos, and otherwise the _Idx-th element in _Storage.
// pre: _Idx + 1 <= remove_reference_t<_Storage>::_Size
constexpr size_t _Size = remove_reference_t<_Storage>::_Size;
constexpr int _Strategy = _Size <= 4 ? 1 : _Size <= 16 ? 2 : _Size <= 64 ? 3 : _Size <= 256 ? 4 : -1;
++_Idx; // bias index by +1 to map {variant_npos} U [0, _Size) to the contiguous range [0, _Size]
return _Variant_raw_visit1<_Strategy>::_Visit(_Idx, static_cast<_Fn&&>(_Func), static_cast<_Storage&&>(_Obj));
}
template <class...>
class _Variant_base;
template <size_t _Count>
using _Variant_index_t = // signed so that conversion of -1 to size_t can cheaply sign extend
conditional_t<(_Count < static_cast<size_t>((numeric_limits<signed char>::max) ())), signed char,
conditional_t<(_Count < static_cast<size_t>((numeric_limits<short>::max) ())), short, int>>;
template <class... _Types>
struct _Variant_construct_visitor { // visitor that constructs the same alternative in a target _Variant_base as is
// currently active in a source _Variant_base from the source's contained value
_Variant_base<_Types...>& _Self;
template <class _Ty, size_t _Idx>
_CONSTEXPR20 void operator()(_Tagged<_Ty, _Idx> _Source) const noexcept(
disjunction_v<bool_constant<_Idx == variant_npos>, is_nothrow_constructible<remove_reference_t<_Ty>, _Ty>>) {
// initialize _Idx-th item in _Self from _Source
_STL_INTERNAL_CHECK(_Self.valueless_by_exception());
(void) _Source; // TRANSITION, DevCom-1004719
if constexpr (_Idx != variant_npos) {
_Construct_in_place(_Self._Storage(), integral_constant<size_t, _Idx>{}, static_cast<_Ty&&>(_Source._Val));
_Self._Set_index(_Idx);
}
}
};
template <class _Target, class... _Types>
inline constexpr bool _Variant_should_directly_construct_v =
disjunction_v<is_nothrow_constructible<_Target, _Types...>, negation<is_nothrow_move_constructible<_Target>>>;
template <class... _Types>
struct _Variant_assign_visitor { // visitor that implements assignment for variants with non-trivial alternatives
_Variant_base<_Types...>& _Self;
template <class _Ty, size_t _Idx>
_CONSTEXPR20 void operator()(_Tagged<_Ty, _Idx> _Source) const
noexcept(disjunction_v<bool_constant<_Idx == variant_npos>,
conjunction<is_nothrow_assignable<_Remove_cvref_t<_Ty>&, _Ty>,
is_nothrow_constructible<_Remove_cvref_t<_Ty>, _Ty>>>) {
// assign the _Idx-th alternative of _Self from _Source
if constexpr (_Idx == variant_npos) { // assign from valueless _Source
(void) _Source; // TRANSITION, DevCom-1004719
_Self._Reset();
} else {
if (_Self._Which == _Idx) { // same alternative: assign directly
auto& _Target = _Variant_raw_get<_Idx>(_Self._Storage());
_Target = static_cast<_Ty&&>(_Source._Val);
} else { // different alternative
if constexpr (is_lvalue_reference_v<_Ty>) { // RHS is an lvalue: copy
if constexpr (_Variant_should_directly_construct_v<_Remove_cvref_t<_Ty>, _Ty>) {
// copy is nothrow or move throws; construct in place
_Self._Reset();
_Construct_in_place(_Self._Storage(), integral_constant<size_t, _Idx>{}, _Source._Val);
} else { // copy throws and move does not; move from a temporary copy
auto _Temp = _Source._Val;
_Self._Reset();
_Construct_in_place(_Self._Storage(), integral_constant<size_t, _Idx>{}, _STD move(_Temp));
}
} else { // RHS is an rvalue: move
_Self._Reset();
_Construct_in_place(
_Self._Storage(), integral_constant<size_t, _Idx>{}, static_cast<_Ty&&>(_Source._Val));
}
_Self._Set_index(_Idx);
}
}
}
};
template <class... _Types> // Associate an integral discriminator with a _Variant_storage
class _Variant_base : private _Variant_storage<_Types...> {
public:
using _Index_t = _Variant_index_t<sizeof...(_Types)>;
static constexpr auto _Invalid_index = static_cast<_Index_t>(-1);
_Index_t _Which;
using _Storage_t = _Variant_storage<_Types...>;
_NODISCARD constexpr _Storage_t& _Storage() & noexcept { // access this variant's storage
return *this;
}
_NODISCARD constexpr const _Storage_t& _Storage() const& noexcept { // access this variant's storage
return *this;
}
_NODISCARD constexpr _Storage_t&& _Storage() && noexcept { // access this variant's storage
return _STD move(*this);
}
_NODISCARD constexpr const _Storage_t&& _Storage() const&& noexcept { // access this variant's storage
return _STD move(*this);
}
// initialize to the value-less state
_CONSTEXPR20 _Variant_base() noexcept : _Storage_t{}, _Which{_Invalid_index} {}
template <size_t _Idx, class... _UTypes,
enable_if_t<is_constructible_v<_Meta_at_c<variant<_Types...>, _Idx>, _UTypes...>, int> = 0>
constexpr explicit _Variant_base(in_place_index_t<_Idx>, _UTypes&&... _Args) noexcept(
is_nothrow_constructible_v<_Meta_at_c<variant<_Types...>, _Idx>, _UTypes...>)
: _Storage_t(integral_constant<size_t, _Idx>{}, static_cast<_UTypes&&>(_Args)...),
_Which{static_cast<_Index_t>(_Idx)} { // initialize alternative _Idx from _Args...
}
_NODISCARD constexpr bool valueless_by_exception() const noexcept { // does this variant NOT hold a value?
return _Which < 0;
}
_NODISCARD constexpr size_t index() const noexcept {
// index of the contained alternative or variant_npos if valueless_by_exception
return static_cast<size_t>(_Which);
}
_CONSTEXPR20 void _Set_index(const size_t _Idx) noexcept {
// record _Idx as the active alternative
// pre: the active alternative of *this is _Idx
_Which = static_cast<_Index_t>(_Idx);
}
template <size_t _Idx>
_CONSTEXPR20 void _Destroy() noexcept {
// destroy the contained value
// pre: _Idx == index()
if constexpr (_Idx != variant_npos && !is_trivially_destructible_v<_Meta_at_c<variant<_Types...>, _Idx>>) {
_Destroy_in_place(_Variant_raw_get<_Idx>(_Storage()));
}
}
_CONSTEXPR20 void _Destroy() noexcept { // destroy the contained value, if any
if constexpr (!conjunction_v<is_trivially_destructible<_Types>...>) {
_Variant_raw_visit(index(), _Storage(), [](auto _Ref) noexcept {
if constexpr (decltype(_Ref)::_Idx != variant_npos) {
_Destroy_in_place(_Ref._Val);
}
});
}
}
_CONSTEXPR20 void _Reset() noexcept { // transition to the valueless_by_exception state
_Destroy();
_Set_index(variant_npos);
}
template <size_t _Idx>
_CONSTEXPR20 void _Reset() noexcept {
// transition to the valueless_by_exception state
// pre: _Idx == index()
if constexpr (_Idx != variant_npos) {
_Destroy<_Idx>();
_Set_index(variant_npos);
}
}
_CONSTEXPR20 void _Construct_from(const _Variant_base& _That) noexcept(
conjunction_v<is_nothrow_copy_constructible<_Types>...>) {
// copy _That's contained value into *this
// pre: valueless_by_exception()
_Variant_raw_visit(_That.index(), _That._Storage(), _Variant_construct_visitor<_Types...>{*this});
}
_CONSTEXPR20 void _Construct_from(_Variant_base&& _That) noexcept(
conjunction_v<is_nothrow_move_constructible<_Types>...>) {
// move _That's contained value into *this
// pre: valueless_by_exception()
_Variant_raw_visit(_That.index(), _STD move(_That)._Storage(), _Variant_construct_visitor<_Types...>{*this});
}
_CONSTEXPR20 void _Assign_from(const _Variant_base& _That) noexcept(
conjunction_v<is_nothrow_copy_constructible<_Types>..., is_nothrow_copy_assignable<_Types>...>) {
// copy assign _That's contained value (if any) into *this
_Variant_raw_visit(_That.index(), _That._Storage(), _Variant_assign_visitor<_Types...>{*this});
}
_CONSTEXPR20 void _Assign_from(_Variant_base&& _That) noexcept(
conjunction_v<is_nothrow_move_constructible<_Types>..., is_nothrow_move_assignable<_Types>...>) {
// move assign _That's contained value (if any) into *this
_Variant_raw_visit(_That.index(), _STD move(_That)._Storage(), _Variant_assign_visitor<_Types...>{*this});
}
};
template <class... _Types>
struct _Variant_destroy_layer_ : _Variant_base<_Types...> { // destruction behavior facade (non-trivial case)
using _Variant_base<_Types...>::_Variant_base;
_CONSTEXPR20 ~_Variant_destroy_layer_() noexcept { // Destroy contained value, if any
this->_Destroy();
}
_Variant_destroy_layer_() = default;
_Variant_destroy_layer_(const _Variant_destroy_layer_&) = default;
_Variant_destroy_layer_(_Variant_destroy_layer_&&) = default;
_Variant_destroy_layer_& operator=(const _Variant_destroy_layer_&) = default;
_Variant_destroy_layer_& operator=(_Variant_destroy_layer_&&) = default;
};
template <class... _Types>
using _Variant_destroy_layer = conditional_t<conjunction_v<is_trivially_destructible<_Types>...>,
_Variant_base<_Types...>, _Variant_destroy_layer_<_Types...>>;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-volatile"
#else // ^^^ Clang / not Clang vvv
#pragma warning(push)
#pragma warning(disable : 4242) // '%s': conversion from '%s' to '%s', possible loss of data
#pragma warning(disable : 4244) // '%s': conversion from '%s' to '%s', possible loss of data (Yes, duplicated message.)
#pragma warning(disable : 4365) // '%s': conversion from '%s' to '%s', signed/unsigned mismatch
#pragma warning(disable : 5215) // '%s' a function parameter with volatile qualified type is deprecated in C++20
#endif // __clang__
#if _HAS_CXX20
// build Ti x[] = {std::forward<T>(t)};
template <size_t _Idx, class _TargetType>
auto _Construct_array(_TargetType(&&)[1]) -> _Meta_list<integral_constant<size_t, _Idx>, _TargetType>;
template <size_t _Idx, class _TargetType, class _InitializerType>
using _Variant_type_resolver = decltype(_Construct_array<_Idx, _TargetType>({_STD declval<_InitializerType>()}));
#endif // _HAS_CXX20
template <size_t _Idx, class _TargetType>
struct _Variant_init_single_overload {
#if _HAS_CXX20
template <class _InitializerType>
auto operator()(_TargetType, _InitializerType&&) -> _Variant_type_resolver<_Idx, _TargetType, _InitializerType>;
#else // _HAS_CXX20
template <class _InitializerType>
auto operator()(_TargetType, _InitializerType&&) -> _Meta_list<integral_constant<size_t, _Idx>, _TargetType>;
#endif // _HAS_CXX20
};
template <class _Indices, class... _Types>
struct _Variant_init_overload_set_;
template <size_t... _Indices, class... _Types>
struct _Variant_init_overload_set_<index_sequence<_Indices...>, _Types...>
: _Variant_init_single_overload<_Indices, _Types>... {
using _Variant_init_single_overload<_Indices, _Types>::operator()...;
};
template <class... _Types>
using _Variant_init_overload_set = _Variant_init_overload_set_<index_sequence_for<_Types...>, _Types...>;
template <class Enable, class _Ty, class... _Types>
struct _Variant_init_helper {}; // failure case (has no member "type")
template <class _Ty, class... _Types>
struct _Variant_init_helper<
void_t<decltype(_Variant_init_overload_set<_Types...>{}(_STD declval<_Ty>(), _STD declval<_Ty>()))>, _Ty,
_Types...> {
// perform overload resolution to determine the unique alternative that should be initialized in
// variant<_Types...> from an argument expression with type and value category _Ty
using type = decltype(_Variant_init_overload_set<_Types...>{}(_STD declval<_Ty>(), _STD declval<_Ty>()));
};
template <class _Ty, class... _Types> // extract the type from _Variant_init_helper
using _Variant_init_type = _Meta_front<_Meta_pop_front<typename _Variant_init_helper<void, _Ty, _Types...>::type>>;
template <class _Ty, class... _Types> // extract the index from _Variant_init_helper
using _Variant_init_index = _Meta_front<typename _Variant_init_helper<void, _Ty, _Types...>::type>;
#ifdef __clang__