mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
tuple
1847 lines (1569 loc) · 60 KB
/
tuple
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
// <tuple> -*- C++ -*-
// Copyright (C) 2007-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file include/tuple
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_TUPLE
#define _GLIBCXX_TUPLE 1
#pragma GCC system_header
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
#include <utility>
#include <array>
#include <bits/uses_allocator.h>
#include <bits/invoke.h>
#if __cplusplus > 201703L
# include <compare>
# define __cpp_lib_constexpr_tuple 201811L
#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @addtogroup utilities
* @{
*/
template<typename... _Elements>
class tuple;
template<typename _Tp>
struct __is_empty_non_tuple : is_empty<_Tp> { };
// Using EBO for elements that are tuples causes ambiguous base errors.
template<typename _El0, typename... _El>
struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
// Use the Empty Base-class Optimization for empty, non-final types.
template<typename _Tp>
using __empty_not_final
= typename conditional<__is_final(_Tp), false_type,
__is_empty_non_tuple<_Tp>>::type;
template<size_t _Idx, typename _Head,
bool = __empty_not_final<_Head>::value>
struct _Head_base;
#if __has_cpp_attribute(no_unique_address)
template<size_t _Idx, typename _Head>
struct _Head_base<_Idx, _Head, true>
{
constexpr _Head_base()
: _M_head_impl() { }
constexpr _Head_base(const _Head& __h)
: _M_head_impl(__h) { }
constexpr _Head_base(const _Head_base&) = default;
constexpr _Head_base(_Head_base&&) = default;
template<typename _UHead>
constexpr _Head_base(_UHead&& __h)
: _M_head_impl(std::forward<_UHead>(__h)) { }
_GLIBCXX20_CONSTEXPR
_Head_base(allocator_arg_t, __uses_alloc0)
: _M_head_impl() { }
template<typename _Alloc>
_Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
: _M_head_impl(allocator_arg, *__a._M_a) { }
template<typename _Alloc>
_Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
: _M_head_impl(*__a._M_a) { }
template<typename _UHead>
_GLIBCXX20_CONSTEXPR
_Head_base(__uses_alloc0, _UHead&& __uhead)
: _M_head_impl(std::forward<_UHead>(__uhead)) { }
template<typename _Alloc, typename _UHead>
_Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
: _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
{ }
template<typename _Alloc, typename _UHead>
_Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
: _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
static constexpr _Head&
_M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
static constexpr const _Head&
_M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
[[__no_unique_address__]] _Head _M_head_impl;
};
#else
template<size_t _Idx, typename _Head>
struct _Head_base<_Idx, _Head, true>
: public _Head
{
constexpr _Head_base()
: _Head() { }
constexpr _Head_base(const _Head& __h)
: _Head(__h) { }
constexpr _Head_base(const _Head_base&) = default;
constexpr _Head_base(_Head_base&&) = default;
template<typename _UHead>
constexpr _Head_base(_UHead&& __h)
: _Head(std::forward<_UHead>(__h)) { }
_Head_base(allocator_arg_t, __uses_alloc0)
: _Head() { }
template<typename _Alloc>
_Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
: _Head(allocator_arg, *__a._M_a) { }
template<typename _Alloc>
_Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
: _Head(*__a._M_a) { }
template<typename _UHead>
_Head_base(__uses_alloc0, _UHead&& __uhead)
: _Head(std::forward<_UHead>(__uhead)) { }
template<typename _Alloc, typename _UHead>
_Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
: _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
template<typename _Alloc, typename _UHead>
_Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
: _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
static constexpr _Head&
_M_head(_Head_base& __b) noexcept { return __b; }
static constexpr const _Head&
_M_head(const _Head_base& __b) noexcept { return __b; }
};
#endif
template<size_t _Idx, typename _Head>
struct _Head_base<_Idx, _Head, false>
{
constexpr _Head_base()
: _M_head_impl() { }
constexpr _Head_base(const _Head& __h)
: _M_head_impl(__h) { }
constexpr _Head_base(const _Head_base&) = default;
constexpr _Head_base(_Head_base&&) = default;
template<typename _UHead>
constexpr _Head_base(_UHead&& __h)
: _M_head_impl(std::forward<_UHead>(__h)) { }
_GLIBCXX20_CONSTEXPR
_Head_base(allocator_arg_t, __uses_alloc0)
: _M_head_impl() { }
template<typename _Alloc>
_Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
: _M_head_impl(allocator_arg, *__a._M_a) { }
template<typename _Alloc>
_Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
: _M_head_impl(*__a._M_a) { }
template<typename _UHead>
_GLIBCXX20_CONSTEXPR
_Head_base(__uses_alloc0, _UHead&& __uhead)
: _M_head_impl(std::forward<_UHead>(__uhead)) { }
template<typename _Alloc, typename _UHead>
_Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
: _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
{ }
template<typename _Alloc, typename _UHead>
_Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
: _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
static constexpr _Head&
_M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
static constexpr const _Head&
_M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
_Head _M_head_impl;
};
/**
* Contains the actual implementation of the @c tuple template, stored
* as a recursive inheritance hierarchy from the first element (most
* derived class) to the last (least derived class). The @c Idx
* parameter gives the 0-based index of the element stored at this
* point in the hierarchy; we use it to implement a constant-time
* get() operation.
*/
template<size_t _Idx, typename... _Elements>
struct _Tuple_impl;
/**
* Recursive tuple implementation. Here we store the @c Head element
* and derive from a @c Tuple_impl containing the remaining elements
* (which contains the @c Tail).
*/
template<size_t _Idx, typename _Head, typename... _Tail>
struct _Tuple_impl<_Idx, _Head, _Tail...>
: public _Tuple_impl<_Idx + 1, _Tail...>,
private _Head_base<_Idx, _Head>
{
template<size_t, typename...> friend struct _Tuple_impl;
typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
typedef _Head_base<_Idx, _Head> _Base;
static constexpr _Head&
_M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
static constexpr const _Head&
_M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
static constexpr _Inherited&
_M_tail(_Tuple_impl& __t) noexcept { return __t; }
static constexpr const _Inherited&
_M_tail(const _Tuple_impl& __t) noexcept { return __t; }
constexpr _Tuple_impl()
: _Inherited(), _Base() { }
explicit constexpr
_Tuple_impl(const _Head& __head, const _Tail&... __tail)
: _Inherited(__tail...), _Base(__head)
{ }
template<typename _UHead, typename... _UTail,
typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
explicit constexpr
_Tuple_impl(_UHead&& __head, _UTail&&... __tail)
: _Inherited(std::forward<_UTail>(__tail)...),
_Base(std::forward<_UHead>(__head))
{ }
constexpr _Tuple_impl(const _Tuple_impl&) = default;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2729. Missing SFINAE on std::pair::operator=
_Tuple_impl& operator=(const _Tuple_impl&) = delete;
constexpr
_Tuple_impl(_Tuple_impl&& __in)
noexcept(__and_<is_nothrow_move_constructible<_Head>,
is_nothrow_move_constructible<_Inherited>>::value)
: _Inherited(std::move(_M_tail(__in))),
_Base(std::forward<_Head>(_M_head(__in)))
{ }
template<typename... _UElements>
constexpr
_Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
: _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
_Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
{ }
template<typename _UHead, typename... _UTails>
constexpr
_Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
: _Inherited(std::move
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
_Base(std::forward<_UHead>
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a),
_Base(__tag, __use_alloc<_Head>(__a))
{ }
template<typename _Alloc>
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Head& __head, const _Tail&... __tail)
: _Inherited(__tag, __a, __tail...),
_Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head)
{ }
template<typename _Alloc, typename _UHead, typename... _UTail,
typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
_UHead&& __head, _UTail&&... __tail)
: _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
_Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
std::forward<_UHead>(__head))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Tuple_impl& __in)
: _Inherited(__tag, __a, _M_tail(__in)),
_Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
_Tuple_impl&& __in)
: _Inherited(__tag, __a, std::move(_M_tail(__in))),
_Base(__use_alloc<_Head, _Alloc, _Head>(__a),
std::forward<_Head>(_M_head(__in)))
{ }
template<typename _Alloc, typename _UHead, typename... _UTails>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
: _Inherited(__tag, __a,
_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
_Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
{ }
template<typename _Alloc, typename _UHead, typename... _UTails>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
: _Inherited(__tag, __a, std::move
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
_Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
std::forward<_UHead>
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
{ }
template<typename... _UElements>
_GLIBCXX20_CONSTEXPR
void
_M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
{
_M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
_M_tail(*this)._M_assign(
_Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
}
template<typename _UHead, typename... _UTails>
_GLIBCXX20_CONSTEXPR
void
_M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
{
_M_head(*this) = std::forward<_UHead>
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
_M_tail(*this)._M_assign(
std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
}
protected:
_GLIBCXX20_CONSTEXPR
void
_M_swap(_Tuple_impl& __in)
{
using std::swap;
swap(_M_head(*this), _M_head(__in));
_Inherited::_M_swap(_M_tail(__in));
}
};
// Basis case of inheritance recursion.
template<size_t _Idx, typename _Head>
struct _Tuple_impl<_Idx, _Head>
: private _Head_base<_Idx, _Head>
{
template<size_t, typename...> friend struct _Tuple_impl;
typedef _Head_base<_Idx, _Head> _Base;
static constexpr _Head&
_M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
static constexpr const _Head&
_M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
constexpr
_Tuple_impl()
: _Base() { }
explicit constexpr
_Tuple_impl(const _Head& __head)
: _Base(__head)
{ }
template<typename _UHead>
explicit constexpr
_Tuple_impl(_UHead&& __head)
: _Base(std::forward<_UHead>(__head))
{ }
constexpr _Tuple_impl(const _Tuple_impl&) = default;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2729. Missing SFINAE on std::pair::operator=
_Tuple_impl& operator=(const _Tuple_impl&) = delete;
constexpr
_Tuple_impl(_Tuple_impl&& __in)
noexcept(is_nothrow_move_constructible<_Head>::value)
: _Base(std::forward<_Head>(_M_head(__in)))
{ }
template<typename _UHead>
constexpr
_Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
: _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
{ }
template<typename _UHead>
constexpr
_Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
: _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
: _Base(__tag, __use_alloc<_Head>(__a))
{ }
template<typename _Alloc>
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Head& __head)
: _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head)
{ }
template<typename _Alloc, typename _UHead>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
_UHead&& __head)
: _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
std::forward<_UHead>(__head))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Tuple_impl& __in)
: _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), _M_head(__in))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
_Tuple_impl&& __in)
: _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
std::forward<_Head>(_M_head(__in)))
{ }
template<typename _Alloc, typename _UHead>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Tuple_impl<_Idx, _UHead>& __in)
: _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
_Tuple_impl<_Idx, _UHead>::_M_head(__in))
{ }
template<typename _Alloc, typename _UHead>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
_Tuple_impl<_Idx, _UHead>&& __in)
: _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
{ }
template<typename _UHead>
_GLIBCXX20_CONSTEXPR
void
_M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
{
_M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
}
template<typename _UHead>
_GLIBCXX20_CONSTEXPR
void
_M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
{
_M_head(*this)
= std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
}
protected:
_GLIBCXX20_CONSTEXPR
void
_M_swap(_Tuple_impl& __in)
{
using std::swap;
swap(_M_head(*this), _M_head(__in));
}
};
// Concept utility functions, reused in conditionally-explicit
// constructors.
template<bool, typename... _Types>
struct _TupleConstraints
{
template<typename _Tp, typename _Up> // Workaround for PR 96592
using is_constructible
= __bool_constant<__is_constructible(_Tp, _Up)>;
// Constraint for a non-explicit constructor.
// True iff each Ti in _Types... can be constructed from Ui in _UTypes...
// and every Ui is implicitly convertible to Ti.
template<typename... _UTypes>
static constexpr bool __is_implicitly_constructible()
{
return __and_<is_constructible<_Types, _UTypes>...,
is_convertible<_UTypes, _Types>...
>::value;
}
// Constraint for a non-explicit constructor.
// True iff each Ti in _Types... can be constructed from Ui in _UTypes...
// but not every Ui is implicitly convertible to Ti.
template<typename... _UTypes>
static constexpr bool __is_explicitly_constructible()
{
return __and_<is_constructible<_Types, _UTypes>...,
__not_<__and_<is_convertible<_UTypes, _Types>...>>
>::value;
}
static constexpr bool __is_implicitly_default_constructible()
{
return __and_<std::__is_implicitly_default_constructible<_Types>...
>::value;
}
static constexpr bool __is_explicitly_default_constructible()
{
return __and_<is_default_constructible<_Types>...,
__not_<__and_<
std::__is_implicitly_default_constructible<_Types>...>
>>::value;
}
};
// Partial specialization used when a required precondition isn't met,
// e.g. when sizeof...(_Types) != sizeof...(_UTypes).
template<typename... _Types>
struct _TupleConstraints<false, _Types...>
{
template<typename... _UTypes>
static constexpr bool __is_implicitly_constructible()
{ return false; }
template<typename... _UTypes>
static constexpr bool __is_explicitly_constructible()
{ return false; }
};
/// Primary class template, tuple
template<typename... _Elements>
class tuple : public _Tuple_impl<0, _Elements...>
{
typedef _Tuple_impl<0, _Elements...> _Inherited;
template<bool _Cond>
using _TCC = _TupleConstraints<_Cond, _Elements...>;
// Constraint for non-explicit default constructor
template<bool _Dummy>
using _ImplicitDefaultCtor = __enable_if_t<
_TCC<_Dummy>::__is_implicitly_default_constructible(),
bool>;
// Constraint for explicit default constructor
template<bool _Dummy>
using _ExplicitDefaultCtor = __enable_if_t<
_TCC<_Dummy>::__is_explicitly_default_constructible(),
bool>;
// Constraint for non-explicit constructors
template<bool _Cond, typename... _Args>
using _ImplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_implicitly_constructible<_Args...>(),
bool>;
// Constraint for non-explicit constructors
template<bool _Cond, typename... _Args>
using _ExplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_explicitly_constructible<_Args...>(),
bool>;
template<typename... _UElements>
static constexpr
__enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
__assignable()
{ return __and_<is_assignable<_Elements&, _UElements>...>::value; }
// Condition for noexcept-specifier of an assignment operator.
template<typename... _UElements>
static constexpr bool __nothrow_assignable()
{
return
__and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
}
// Condition for noexcept-specifier of a constructor.
template<typename... _UElements>
static constexpr bool __nothrow_constructible()
{
return
__and_<is_nothrow_constructible<_Elements, _UElements>...>::value;
}
// Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) == 1.
template<typename _Up>
static constexpr bool __valid_args()
{
return sizeof...(_Elements) == 1
&& !is_same<tuple, __remove_cvref_t<_Up>>::value;
}
// Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) > 1.
template<typename, typename, typename... _Tail>
static constexpr bool __valid_args()
{ return (sizeof...(_Tail) + 2) == sizeof...(_Elements); }
/* Constraint for constructors with a tuple<UTypes...> parameter ensures
* that the constructor is only viable when it would not interfere with
* tuple(UTypes&&...) or tuple(const tuple&) or tuple(tuple&&).
* Such constructors are only viable if:
* either sizeof...(Types) != 1,
* or (when Types... expands to T and UTypes... expands to U)
* is_convertible_v<TUPLE, T>, is_constructible_v<T, TUPLE>,
* and is_same_v<T, U> are all false.
*/
template<typename _Tuple, typename = tuple,
typename = __remove_cvref_t<_Tuple>>
struct _UseOtherCtor
: false_type
{ };
// If TUPLE is convertible to the single element in *this,
// then TUPLE should match tuple(UTypes&&...) instead.
template<typename _Tuple, typename _Tp, typename _Up>
struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Up>>
: __or_<is_convertible<_Tuple, _Tp>, is_constructible<_Tp, _Tuple>>
{ };
// If TUPLE and *this each have a single element of the same type,
// then TUPLE should match a copy/move constructor instead.
template<typename _Tuple, typename _Tp>
struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Tp>>
: true_type
{ };
// Return true iff sizeof...(Types) == 1 && tuple_size_v<TUPLE> == 1
// and the single element in Types can be initialized from TUPLE,
// or is the same type as tuple_element_t<0, TUPLE>.
template<typename _Tuple>
static constexpr bool __use_other_ctor()
{ return _UseOtherCtor<_Tuple>::value; }
public:
template<typename _Dummy = void,
_ImplicitDefaultCtor<is_void<_Dummy>::value> = true>
constexpr
tuple()
noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
: _Inherited() { }
template<typename _Dummy = void,
_ExplicitDefaultCtor<is_void<_Dummy>::value> = false>
explicit constexpr
tuple()
noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
: _Inherited() { }
template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ImplicitCtor<_NotEmpty, const _Elements&...> = true>
constexpr
tuple(const _Elements&... __elements)
noexcept(__nothrow_constructible<const _Elements&...>())
: _Inherited(__elements...) { }
template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ExplicitCtor<_NotEmpty, const _Elements&...> = false>
explicit constexpr
tuple(const _Elements&... __elements)
noexcept(__nothrow_constructible<const _Elements&...>())
: _Inherited(__elements...) { }
template<typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ImplicitCtor<_Valid, _UElements...> = true>
constexpr
tuple(_UElements&&... __elements)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(std::forward<_UElements>(__elements)...) { }
template<typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ExplicitCtor<_Valid, _UElements...> = false>
explicit constexpr
tuple(_UElements&&... __elements)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(std::forward<_UElements>(__elements)...) { }
constexpr tuple(const tuple&) = default;
constexpr tuple(tuple&&) = default;
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ImplicitCtor<_Valid, const _UElements&...> = true>
constexpr
tuple(const tuple<_UElements...>& __in)
noexcept(__nothrow_constructible<const _UElements&...>())
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ExplicitCtor<_Valid, const _UElements&...> = false>
explicit constexpr
tuple(const tuple<_UElements...>& __in)
noexcept(__nothrow_constructible<const _UElements&...>())
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ImplicitCtor<_Valid, _UElements...> = true>
constexpr
tuple(tuple<_UElements...>&& __in)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ExplicitCtor<_Valid, _UElements...> = false>
explicit constexpr
tuple(tuple<_UElements...>&& __in)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
// Allocator-extended constructors.
template<typename _Alloc,
_ImplicitDefaultCtor<is_object<_Alloc>::value> = true>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a) { }
template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ImplicitCtor<_NotEmpty, const _Elements&...> = true>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a,
const _Elements&... __elements)
: _Inherited(__tag, __a, __elements...) { }
template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ExplicitCtor<_NotEmpty, const _Elements&...> = false>
_GLIBCXX20_CONSTEXPR
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const _Elements&... __elements)
: _Inherited(__tag, __a, __elements...) { }
template<typename _Alloc, typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ImplicitCtor<_Valid, _UElements...> = true>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a,
_UElements&&... __elements)
: _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
{ }
template<typename _Alloc, typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ExplicitCtor<_Valid, _UElements...> = false>
_GLIBCXX20_CONSTEXPR
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
_UElements&&... __elements)
: _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
: _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
: _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ImplicitCtor<_Valid, const _UElements&...> = true>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a,
const tuple<_UElements...>& __in)
: _Inherited(__tag, __a,
static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ExplicitCtor<_Valid, const _UElements&...> = false>
_GLIBCXX20_CONSTEXPR
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const tuple<_UElements...>& __in)
: _Inherited(__tag, __a,
static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ImplicitCtor<_Valid, _UElements...> = true>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t __tag, const _Alloc& __a,
tuple<_UElements...>&& __in)
: _Inherited(__tag, __a,
static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
{ }
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ExplicitCtor<_Valid, _UElements...> = false>
_GLIBCXX20_CONSTEXPR
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
tuple<_UElements...>&& __in)
: _Inherited(__tag, __a,
static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
{ }
// tuple assignment
_GLIBCXX20_CONSTEXPR
tuple&
operator=(typename conditional<__assignable<const _Elements&...>(),
const tuple&,
const __nonesuch&>::type __in)
noexcept(__nothrow_assignable<const _Elements&...>())
{
this->_M_assign(__in);
return *this;
}
_GLIBCXX20_CONSTEXPR
tuple&
operator=(typename conditional<__assignable<_Elements...>(),
tuple&&,
__nonesuch&&>::type __in)
noexcept(__nothrow_assignable<_Elements...>())
{
this->_M_assign(std::move(__in));
return *this;
}
template<typename... _UElements>
_GLIBCXX20_CONSTEXPR
__enable_if_t<__assignable<const _UElements&...>(), tuple&>
operator=(const tuple<_UElements...>& __in)
noexcept(__nothrow_assignable<const _UElements&...>())
{
this->_M_assign(__in);
return *this;
}
template<typename... _UElements>
_GLIBCXX20_CONSTEXPR
__enable_if_t<__assignable<_UElements...>(), tuple&>
operator=(tuple<_UElements...>&& __in)
noexcept(__nothrow_assignable<_UElements...>())
{
this->_M_assign(std::move(__in));
return *this;
}
// tuple swap
_GLIBCXX20_CONSTEXPR
void
swap(tuple& __in)
noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value)
{ _Inherited::_M_swap(__in); }
};
#if __cpp_deduction_guides >= 201606
template<typename... _UTypes>
tuple(_UTypes...) -> tuple<_UTypes...>;
template<typename _T1, typename _T2>
tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
template<typename _Alloc, typename... _UTypes>
tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
template<typename _Alloc, typename _T1, typename _T2>
tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
template<typename _Alloc, typename... _UTypes>
tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
#endif
// Explicit specialization, zero-element tuple.
template<>
class tuple<>
{
public:
void swap(tuple&) noexcept { /* no-op */ }
// We need the default since we're going to define no-op
// allocator constructors.
tuple() = default;
// No-op allocator constructors.
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t, const _Alloc&) noexcept { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept { }
};
/// Partial specialization, 2-element tuple.
/// Includes construction and assignment from a pair.
template<typename _T1, typename _T2>
class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
{
typedef _Tuple_impl<0, _T1, _T2> _Inherited;
// Constraint for non-explicit default constructor
template<bool _Dummy, typename _U1, typename _U2>
using _ImplicitDefaultCtor = __enable_if_t<
_TupleConstraints<_Dummy, _U1, _U2>::
__is_implicitly_default_constructible(),
bool>;
// Constraint for explicit default constructor
template<bool _Dummy, typename _U1, typename _U2>
using _ExplicitDefaultCtor = __enable_if_t<
_TupleConstraints<_Dummy, _U1, _U2>::
__is_explicitly_default_constructible(),
bool>;
template<bool _Dummy>
using _TCC = _TupleConstraints<_Dummy, _T1, _T2>;
// Constraint for non-explicit constructors
template<bool _Cond, typename _U1, typename _U2>
using _ImplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_implicitly_constructible<_U1, _U2>(),
bool>;
// Constraint for non-explicit constructors
template<bool _Cond, typename _U1, typename _U2>
using _ExplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_explicitly_constructible<_U1, _U2>(),