summaryrefslogtreecommitdiffstats
path: root/include/type_traits
blob: b838b17628c4b366988a30ba83d8253c443fecdf (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
// -*- C++ -*-
//===------------------------ type_traits ---------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_TYPE_TRAITS
#define _LIBCPP_TYPE_TRAITS

/*
    type_traits synopsis

namespace std
{

    // helper class:
    template <class T, T v> struct integral_constant;
    typedef integral_constant<bool, true>  true_type;
    typedef integral_constant<bool, false> false_type;

    // helper traits
    template <bool, class T = void> struct enable_if;
    template <bool, class T, class F> struct conditional;

    // Primary classification traits:
    template <class T> struct is_void;
    template <class T> struct is_integral;
    template <class T> struct is_floating_point;
    template <class T> struct is_array;
    template <class T> struct is_pointer;
    template <class T> struct is_lvalue_reference;
    template <class T> struct is_rvalue_reference;
    template <class T> struct is_reference;
    template <class T> struct is_member_object_pointer;
    template <class T> struct is_member_function_pointer;
    template <class T> struct is_enum;
    template <class T> struct is_union;
    template <class T> struct is_class;
    template <class T> struct is_function;
    
    // Secondary classification traits:
    template <class T> struct is_reference;
    template <class T> struct is_arithmetic;
    template <class T> struct is_fundamental;
    template <class T> struct is_member_pointer;
    template <class T> struct is_scalar;
    template <class T> struct is_object;
    template <class T> struct is_compound;
    
    // Const-volatile properties and transformations:
    template <class T> struct is_const;
    template <class T> struct is_volatile;
    template <class T> struct remove_const;
    template <class T> struct remove_volatile;
    template <class T> struct remove_cv;
    template <class T> struct add_const;
    template <class T> struct add_volatile;
    template <class T> struct add_cv;
    
    // Reference transformations:
    template <class T> struct remove_reference;
    template <class T> struct add_lvalue_reference;
    template <class T> struct add_rvalue_reference;
    
    // Pointer transformations:
    template <class T> struct remove_pointer;
    template <class T> struct add_pointer;
    
    // Integral properties:
    template <class T> struct is_signed;
    template <class T> struct is_unsigned;
    template <class T> struct make_signed;
    template <class T> struct make_unsigned;
    
    // Array properties and transformations:
    template <class T> struct rank;
    template <class T, unsigned I = 0> struct extent;
    template <class T> struct remove_extent;
    template <class T> struct remove_all_extents;
    
    // Member introspection:
    template <class T> struct is_pod;
    template <class T> struct is_trivial;
    template <class T> struct is_trivially_copyable;
    template <class T> struct is_standard_layout;
    template <class T> struct is_literal_type;
    template <class T> struct is_empty;
    template <class T> struct is_polymorphic;
    template <class T> struct is_abstract;
    template <class T, class... Args> struct is_constructible;
    template <class T, class... Args> struct is_nothrow_constructible;
    template <class T> struct has_default_constructor;
    template <class T> struct has_copy_constructor;
    template <class T> struct has_move_constructor;
    template <class T> struct has_copy_assign;
    template <class T> struct has_move_assign;
    template <class T> struct has_trivial_default_constructor
    template <class T> struct has_trivial_copy_constructor;
    template <class T> struct has_trivial_move_constructor;
    template <class T> struct has_trivial_copy_assign;
    template <class T> struct has_trivial_move_assign;
    template <class T> struct has_trivial_destructor;
    template <class T> struct has_nothrow_default_constructor;
    template <class T> struct has_nothrow_copy_constructor;
    template <class T> struct has_nothrow_move_constructor;
    template <class T> struct has_nothrow_copy_assign;
    template <class T> struct has_nothrow_move_assign;
    template <class T> struct has_virtual_destructor;
    
    // Relationships between types:
    template <class T, class U> struct is_same;
    template <class Base, class Derived> struct is_base_of;
    template <class From, class To> struct is_convertible;
    template <class From, class To> struct is_explicitly_convertible;
    template <class T> struct underlying_type;
    
    // Alignment properties and transformations:
    template <class T> struct alignment_of;
    template <size_t Len, size_t Align = most_stringent_alignment_requirement>
        struct aligned_storage;
    template <std::size_t Len, class... Types> struct aligned_union;

    template <class T> struct decay;
    template <class... T> struct common_type;
    template <class T> struct underlying_type;
    template <class> class result_of; // undefined
    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;

}  // std

*/
#include <__config>
#include <cstddef>

#pragma GCC system_header

_LIBCPP_BEGIN_NAMESPACE_STD

template <bool _B, class _If, class _Then> struct conditional           {typedef _If type;};
template <class _If, class _Then> struct conditional<false, _If, _Then> {typedef _Then type;};

template <bool, class _Tp = void> struct enable_if {};
template <class _Tp> struct enable_if<true, _Tp> {typedef _Tp type;};

struct __two {char _[2];};

// helper class:

template <class _Tp, _Tp __v>
struct integral_constant
{
    static const _Tp          value = __v;
    typedef _Tp               value_type;
    typedef integral_constant type;
};

template <class _Tp, _Tp __v>
const _Tp integral_constant<_Tp, __v>::value;

typedef integral_constant<bool, true>  true_type;
typedef integral_constant<bool, false> false_type;

// is_const

template <class _Tp> struct is_const            : public false_type {};
template <class _Tp> struct is_const<_Tp const> : public true_type {};

// is_volatile

template <class _Tp> struct is_volatile               : public false_type {};
template <class _Tp> struct is_volatile<_Tp volatile> : public true_type {};

// remove_const

template <class _Tp> struct remove_const            {typedef _Tp type;};
template <class _Tp> struct remove_const<const _Tp> {typedef _Tp type;};

// remove_volatile

template <class _Tp> struct remove_volatile               {typedef _Tp type;};
template <class _Tp> struct remove_volatile<volatile _Tp> {typedef _Tp type;};

// remove_cv

template <class _Tp> struct remove_cv
{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};

// is_void

template <class _Tp> struct __is_void       : public false_type {};
template <>          struct __is_void<void> : public true_type {};

template <class _Tp> struct is_void : public __is_void<typename remove_cv<_Tp>::type> {};

// is_integral

template <class _Tp> struct __is_integral                     : public false_type {};
template <>          struct __is_integral<bool>               : public true_type {};
template <>          struct __is_integral<char>               : public true_type {};
template <>          struct __is_integral<signed char>        : public true_type {};
template <>          struct __is_integral<unsigned char>      : public true_type {};
template <>          struct __is_integral<wchar_t>            : public true_type {};
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
template <>          struct __is_integral<char16_t>           : public true_type {};
template <>          struct __is_integral<char32_t>           : public true_type {};
#endif
template <>          struct __is_integral<short>              : public true_type {};
template <>          struct __is_integral<unsigned short>     : public true_type {};
template <>          struct __is_integral<int>                : public true_type {};
template <>          struct __is_integral<unsigned int>       : public true_type {};
template <>          struct __is_integral<long>               : public true_type {};
template <>          struct __is_integral<unsigned long>      : public true_type {};
template <>          struct __is_integral<long long>          : public true_type {};
template <>          struct __is_integral<unsigned long long> : public true_type {};

template <class _Tp> struct is_integral : public __is_integral<typename remove_cv<_Tp>::type> {};

// is_floating_point

template <class _Tp> struct __is_floating_point              : public false_type {};
template <>          struct __is_floating_point<float>       : public true_type {};
template <>          struct __is_floating_point<double>      : public true_type {};
template <>          struct __is_floating_point<long double> : public true_type {};

template <class _Tp> struct is_floating_point : public __is_floating_point<typename remove_cv<_Tp>::type> {};

// is_array

template <class _Tp> struct            is_array            : public false_type {};
template <class _Tp> struct            is_array<_Tp[]>     : public true_type {};
template <class _Tp, size_t _Np> struct is_array<_Tp[_Np]> : public true_type {};

// is_pointer

template <class _Tp> struct __is_pointer       : public false_type {};
template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};

template <class _Tp> struct is_pointer : public __is_pointer<typename remove_cv<_Tp>::type> {};

// is_reference

template <class _Tp> struct is_lvalue_reference       : public false_type {};
template <class _Tp> struct is_lvalue_reference<_Tp&> : public true_type {};

template <class _Tp> struct is_rvalue_reference        : public false_type {};
#ifdef _LIBCPP_MOVE
template <class _Tp> struct is_rvalue_reference<_Tp&&> : public true_type {};
#endif

template <class _Tp> struct is_reference        : public false_type {};
template <class _Tp> struct is_reference<_Tp&>  : public true_type {};
#ifdef _LIBCPP_MOVE
template <class _Tp> struct is_reference<_Tp&&> : public true_type {};
#endif

// is_union

#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3

template <class _Tp> struct is_union : public integral_constant<bool, __is_union(_Tp)> {};

#else

template <class _Tp> struct __libcpp_union : public false_type {};
template <class _Tp> struct is_union : public __libcpp_union<typename remove_cv<_Tp>::type> {};

#endif

// is_class

namespace __is_class_imp
{
template <class _Tp> char  __test(int _Tp::*);
template <class _Tp> __two __test(...);
}

template <class _Tp> struct is_class
    : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};

// is_function

namespace __is_function_imp
{
template <class _Tp> char  __test(_Tp*);
template <class _Tp> __two __test(...);
template <class _Tp> _Tp&  __source();
}

template <class _Tp, bool = is_class<_Tp>::value ||
                            is_union<_Tp>::value ||
                            is_void<_Tp>::value  ||
                            is_reference<_Tp>::value>
struct __is_function
    : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
    {};
template <class _Tp> struct __is_function<_Tp, true> : public false_type {};

template <class _Tp> struct is_function : public __is_function<_Tp> {};

// is_member_function_pointer

template <class _Tp> struct            __is_member_function_pointer             : public false_type {};
template <class _Tp, class _Up> struct __is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};

template <class _Tp> struct is_member_function_pointer
    : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};

// is_member_pointer

template <class _Tp>            struct __is_member_pointer             : public false_type {};
template <class _Tp, class _Up> struct __is_member_pointer<_Tp _Up::*> : public true_type {};

template <class _Tp> struct is_member_pointer
    : public __is_member_pointer<typename remove_cv<_Tp>::type> {};

// is_member_object_pointer

template <class _Tp> struct is_member_object_pointer
    : public integral_constant<bool, is_member_pointer<_Tp>::value &&
                                    !is_member_function_pointer<_Tp>::value> {};

// is_enum

template <class _Tp> struct is_enum
    : public integral_constant<bool, !is_void<_Tp>::value             &&
                                     !is_integral<_Tp>::value         &&
                                     !is_floating_point<_Tp>::value   &&
                                     !is_array<_Tp>::value            &&
                                     !is_pointer<_Tp>::value          &&
                                     !is_reference<_Tp>::value        &&
                                     !is_member_pointer<_Tp>::value   &&
                                     !is_union<_Tp>::value            &&
                                     !is_class<_Tp>::value            &&
                                     !is_function<_Tp>::value         > {};

// is_arithmetic

template <class _Tp> struct is_arithmetic
    : public integral_constant<bool, is_integral<_Tp>::value      ||
                                     is_floating_point<_Tp>::value> {};

// is_fundamental

template <class _Tp> struct is_fundamental
    : public integral_constant<bool, is_void<_Tp>::value      ||
                                     is_arithmetic<_Tp>::value> {};

// is_scalar

template <class _Tp> struct is_scalar
    : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
                                     is_member_pointer<_Tp>::value ||
                                     is_pointer<_Tp>::value        ||
                                     is_enum<_Tp>::value           > {};

// is_object

template <class _Tp> struct is_object
    : public integral_constant<bool, is_scalar<_Tp>::value ||
                                     is_array<_Tp>::value  ||
                                     is_union<_Tp>::value  ||
                                     is_class<_Tp>::value  > {};

// is_compound

template <class _Tp> struct is_compound : public integral_constant<bool, !is_fundamental<_Tp>::value> {};

// add_const

template <class _Tp, bool = is_reference<_Tp>::value ||
                            is_function<_Tp>::value  ||
                            is_const<_Tp>::value     >
struct __add_const             {typedef _Tp type;};

template <class _Tp>
struct __add_const<_Tp, false> {typedef const _Tp type;};

template <class _Tp> struct add_const {typedef typename __add_const<_Tp>::type type;};

// add_volatile

template <class _Tp, bool = is_reference<_Tp>::value ||
                            is_function<_Tp>::value  ||
                            is_volatile<_Tp>::value  >
struct __add_volatile             {typedef _Tp type;};

template <class _Tp>
struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};

template <class _Tp> struct add_volatile {typedef typename __add_volatile<_Tp>::type type;};

// add_cv

template <class T> struct add_cv {typedef typename add_const<typename add_volatile<T>::type>::type type;};

// remove_reference

template <class _Tp> struct remove_reference        {typedef _Tp type;};
template <class _Tp> struct remove_reference<_Tp&>  {typedef _Tp type;};
#ifdef _LIBCPP_MOVE
template <class _Tp> struct remove_reference<_Tp&&> {typedef _Tp type;};
#endif

// add_lvalue_reference

template <class _Tp> struct add_lvalue_reference                      {typedef _Tp& type;};
template <class _Tp> struct add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
template <>          struct add_lvalue_reference<void>                {typedef void type;};
template <>          struct add_lvalue_reference<const void>          {typedef const void type;};
template <>          struct add_lvalue_reference<volatile void>       {typedef volatile void type;};
template <>          struct add_lvalue_reference<const volatile void> {typedef const volatile void type;};

#ifdef _LIBCPP_MOVE

template <class _Tp> struct add_rvalue_reference                      {typedef _Tp&& type;};
template <>          struct add_rvalue_reference<void>                {typedef void type;};
template <>          struct add_rvalue_reference<const void>          {typedef const void type;};
template <>          struct add_rvalue_reference<volatile void>       {typedef volatile void type;};
template <>          struct add_rvalue_reference<const volatile void> {typedef const volatile void type;};

#endif

// remove_pointer

template <class _Tp> struct remove_pointer                      {typedef _Tp type;};
template <class _Tp> struct remove_pointer<_Tp*>                {typedef _Tp type;};
template <class _Tp> struct remove_pointer<_Tp* const>          {typedef _Tp type;};
template <class _Tp> struct remove_pointer<_Tp* volatile>       {typedef _Tp type;};
template <class _Tp> struct remove_pointer<_Tp* const volatile> {typedef _Tp type;};

// add_pointer

template <class _Tp> struct add_pointer {typedef typename remove_reference<_Tp>::type* type;};

// is_signed

template <class _Tp, bool = is_integral<_Tp>::value>
struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};

template <class _Tp>
struct ___is_signed<_Tp, false> : public true_type {};  // floating point

template <class _Tp, bool = is_arithmetic<_Tp>::value>
struct __is_signed : public ___is_signed<_Tp> {};

template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};

template <class _Tp> struct is_signed : public __is_signed<_Tp> {};

// is_unsigned

template <class _Tp, bool = is_integral<_Tp>::value>
struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};

template <class _Tp>
struct ___is_unsigned<_Tp, false> : public false_type {};  // floating point

template <class _Tp, bool = is_arithmetic<_Tp>::value>
struct __is_unsigned : public ___is_unsigned<_Tp> {};

template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};

template <class _Tp> struct is_unsigned : public __is_unsigned<_Tp> {};

// rank

template <class _Tp> struct rank                       : public integral_constant<size_t, 0> {};
template <class _Tp> struct rank<_Tp[]>                : public integral_constant<size_t, rank<_Tp>::value + 1> {};
template <class _Tp, size_t _Np> struct rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};

// extent

template <class _Tp, unsigned _Ip = 0>         struct extent                : public integral_constant<size_t, 0> {};
template <class _Tp>                           struct extent<_Tp[], 0>      : public integral_constant<size_t, 0> {};
template <class _Tp, unsigned _Ip>             struct extent<_Tp[], _Ip>    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
template <class _Tp, size_t _Np>               struct extent<_Tp[_Np], 0>   : public integral_constant<size_t, _Np> {};
template <class _Tp, size_t _Np, unsigned _Ip> struct extent<_Tp[_Np], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};

// remove_extent

template <class _Tp>             struct remove_extent           {typedef _Tp type;};
template <class _Tp>             struct remove_extent<_Tp[]>    {typedef _Tp type;};
template <class _Tp, size_t _Np> struct remove_extent<_Tp[_Np]> {typedef _Tp type;};

// remove_all_extents

template <class _Tp>             struct remove_all_extents           {typedef _Tp type;};
template <class _Tp>             struct remove_all_extents<_Tp[]>    {typedef typename remove_all_extents<_Tp>::type type;};
template <class _Tp, size_t _Np> struct remove_all_extents<_Tp[_Np]> {typedef typename remove_all_extents<_Tp>::type type;};

// is_same

template <class _Tp, class _Up> struct is_same           : public false_type {};
template <class _Tp>            struct is_same<_Tp, _Tp> : public true_type {};

// is_abstract

namespace __is_abstract_imp
{
template <class _Tp> char  __test(_Tp (*)[1]);
template <class _Tp> __two __test(...);
}

template <class _Tp, bool = is_class<_Tp>::value>
struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};

template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};

template <class _Tp> struct is_abstract : public __libcpp_abstract<_Tp> {};

// is_convertible

namespace __is_convertible_imp
{
#ifdef _LIBCPP_MOVE
template <class _Tp> char  __test(const volatile typename remove_reference<_Tp>::type&&);
#else
template <class _Tp> char  __test(_Tp);
#endif
template <class _Tp> __two __test(...);
#ifdef _LIBCPP_MOVE
template <class _Tp> _Tp&& __source();
#else
template <class _Tp> typename remove_reference<_Tp>::type& __source();
#endif

template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
                     bool _IsFunction = is_function<_Tp>::value,
                     bool _IsVoid =     is_void<_Tp>::value>
                     struct __is_array_function_or_void                          {enum {value = 0};};
template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
}

template <class _Tp,
    unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
struct __is_convertible_check
{
    static const size_t __v = 0;
};

template <class _Tp>
struct __is_convertible_check<_Tp, 0>
{
    static const size_t __v = sizeof(_Tp);
};

template <class _T1, class _T2,
    unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
    unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
struct __is_convertible
    : public integral_constant<bool,
        sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
    >
{};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};

template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
#ifdef _LIBCPP_MOVE
template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
#endif

template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};


template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
#ifdef _LIBCPP_MOVE
template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
#endif
template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
template <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};

template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};

template <class _T1, class _T2> struct is_convertible : public __is_convertible<_T1, _T2>
{
    static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
    static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
};

// is_base_of

//  (C) Copyright Rani Sharoni 2003.
//  Use, modification and distribution are subject to the Boost Software License,
//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt).
//
//  See http://www.boost.org/libs/type_traits for most recent version including documentation.

template <class _Bp, class _Dp>
struct __is_base_of_tests
{
    template <class _Tp>
    static char  __test(const volatile _Dp*, _Tp);
    static __two __test(const volatile _Bp*, int);
};

template <class _Bp, class _Dp>
struct __is_base_of_imp
{
    struct __host
    {
        operator const volatile _Bp*() const;
        operator const volatile _Dp*();
    };

    static const size_t __complete_check = sizeof(_Dp);
    static const bool value = sizeof(__is_base_of_tests<_Bp, _Dp>::__test(__host(), 0)) == 1;
};

template <class _Bp, class _Dp, bool = is_class<_Bp>::value,
                                bool = is_class<_Dp>::value,
                                bool = is_same<_Bp, _Dp>::value>
struct __libcpp_base_of : public false_type {};

template <class _Bp, class _Dp>
struct __libcpp_base_of<_Bp, _Dp, true, true, true> : public true_type {};

template <class _Bp, class _Dp>
struct __libcpp_base_of<_Bp, _Dp, true, true, false>
    : public integral_constant<bool, __is_base_of_imp<_Bp, _Dp>::value> {};

template <class _Bp, class _Dp>
struct is_base_of
    : public __libcpp_base_of<typename remove_cv<_Bp>::type, typename remove_cv<_Dp>::type>
{
};

// is_empty

template <class _Tp>
struct __is_empty1
    : public _Tp
{
    double _;
};

struct __is_empty2
{
    double _;
};

template <class _Tp, bool = is_class<_Tp>::value>
struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};

template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};

template <class _Tp> struct is_empty : public __libcpp_empty<_Tp> {};

// is_polymorphic

template <class _Tp> struct __is_polymorphic1 : public _Tp {};
template <class _Tp> struct __is_polymorphic2 : public _Tp {virtual ~__is_polymorphic2() throw();};

template <class _Tp, bool = is_class<_Tp>::value>
struct __libcpp_polymorphic
    : public integral_constant<bool, sizeof(__is_polymorphic1<_Tp>) == sizeof(__is_polymorphic2<_Tp>)> {};

template <class _Tp> struct __libcpp_polymorphic<_Tp, false> : public false_type {};

template <class _Tp> struct is_polymorphic : public __libcpp_polymorphic<_Tp> {};

// has_trivial_default_constructor

template <class _Tp> struct __has_trivial_default_constructor : public integral_constant<bool, is_scalar<_Tp>::value> {};

template <class _Tp> struct has_trivial_default_constructor
    : public __has_trivial_default_constructor<typename remove_all_extents<_Tp>::type> {};

// has_nothrow_default_constructor

template <class _Tp> struct has_nothrow_default_constructor : public has_trivial_default_constructor<_Tp> {};

// has_trivial_copy_constructor

template <class _Tp> struct __has_trivial_copy_constructor : public integral_constant<bool, is_scalar<_Tp>::value ||
                                                                                is_reference<_Tp>::value> {};

template <class _Tp> struct has_trivial_copy_constructor
    : public __has_trivial_copy_constructor<typename remove_all_extents<_Tp>::type> {};

// has_nothrow_copy_constructor

template <class _Tp> struct has_nothrow_copy_constructor : public has_trivial_copy_constructor<_Tp> {};

// has_nothrow_move_constructor

template <class _Tp> struct has_nothrow_move_constructor : public has_nothrow_copy_constructor<_Tp> {};

// has_copy_constructor

template <class _Tp> struct has_copy_constructor : public true_type {};

// has_trivial_copy_assign

template <class _Tp> struct __libcpp_trivial_copy_assign : public integral_constant<bool, !is_const<_Tp>::value &&
                                                                                   is_scalar<_Tp>::value> {};

template <class _Tp> struct has_trivial_copy_assign
    : public __libcpp_trivial_copy_assign<typename remove_all_extents<_Tp>::type> {};

// has_nothrow_copy_assign

template <class _Tp> struct has_nothrow_copy_assign: public has_trivial_copy_assign<_Tp> {};

// has_trivial_destructor

template <class _Tp> struct __libcpp_trivial_destructor : public integral_constant<bool, is_scalar<_Tp>::value ||
                                                                                      is_reference<_Tp>::value> {};

template <class _Tp> struct has_trivial_destructor
    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};

// has_virtual_destructor

template <class _Tp> struct has_virtual_destructor : public false_type {};

// is_pod

template <class _Tp> struct is_pod : public integral_constant<bool, has_trivial_default_constructor<_Tp>::value   &&
                                                                    has_trivial_copy_constructor<_Tp>::value      &&
                                                                    has_trivial_copy_assign<_Tp>::value    &&
                                                                    has_trivial_destructor<_Tp>::value> {};

// alignment_of

template <class _Tp> struct __alignment_of {_Tp _;};

template <class _Tp> struct alignment_of
    : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {};

// aligned_storage

template <class _Hp, class _Tp>
struct __type_list
{
    typedef _Hp _Head;
    typedef _Tp _Tail;
};

struct __nat {};

template <class _Tp>
struct __align_type
{
    static const size_t value = alignment_of<_Tp>::value;
    typedef _Tp type;
};

struct __struct_double {long double _;};
struct __struct_double4 {double _[4];};

typedef
    __type_list<__align_type<unsigned char>,
    __type_list<__align_type<unsigned short>,
    __type_list<__align_type<unsigned int>,
    __type_list<__align_type<unsigned long>,
    __type_list<__align_type<unsigned long long>,
    __type_list<__align_type<double>,
    __type_list<__align_type<long double>,
    __type_list<__align_type<__struct_double>,
    __type_list<__align_type<__struct_double4>,
    __type_list<__align_type<int*>,
    __nat
    > > > > > > > > > > __all_types;

template <class _TL, size_t _Align> struct __find_pod;

template <class _Hp, size_t _Align>
struct __find_pod<__type_list<_Hp, __nat>, _Align>
{
    typedef typename conditional<
                             _Align == _Hp::value,
                             typename _Hp::type,
                             void
                         >::type type;
};

template <class _Hp, class _Tp, size_t _Align>
struct __find_pod<__type_list<_Hp, _Tp>, _Align>
{
    typedef typename conditional<
                             _Align == _Hp::value,
                             typename _Hp::type,
                             typename __find_pod<_Tp, _Align>::type
                         >::type type;
};

template <class _TL, size_t _Len> struct __find_max_align;

template <class _Hp, size_t _Len>
struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};

template <size_t _Len, size_t _A1, size_t _A2>
struct __select_align
{
private:
    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
public:
    static const size_t value = _Len < __max ? __min : __max;
};

template <class _Hp, class _Tp, size_t _Len>
struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};

template <size_t _Len, const size_t _Align = __find_max_align<__all_types, _Len>::value>
struct aligned_storage
{
    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
    static_assert(!is_void<_Aligner>::value, "");
    union type
    {
        _Aligner __align;
        unsigned char __data[_Len];
    };
};

#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
template <size_t _Len>\
struct aligned_storage<_Len, n>\
{\
    struct type\
    {\
        unsigned char _[_Len];\
    } __attribute__((__aligned__(n)));\
}

_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);

#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION

// __promote

template <class _A1, class _A2 = void, class _A3 = void,
          bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
                 (is_arithmetic<_A3>::value || is_void<_A3>::value)>
class __promote {};


template <class _A1, class _A2, class _A3>
class __promote<_A1, _A2, _A3, true>
{
private:
    typedef typename __promote<_A1>::type __type1;
    typedef typename __promote<_A2>::type __type2;
    typedef typename __promote<_A3>::type __type3;
public:
    typedef __typeof__(__type1() + __type2() + __type3()) type;
};

template <class _A1, class _A2>
class __promote<_A1, _A2, void, true>
{
private:
    typedef typename __promote<_A1>::type __type1;
    typedef typename __promote<_A2>::type __type2;
public:
    typedef __typeof__(__type1() + __type2()) type;
};

template <class _A1>
class __promote<_A1, void, void, true>
{
public:
    typedef typename conditional<is_arithmetic<_A1>::value,
                     typename conditional<is_integral<_A1>::value, double, _A1>::type,
                     void
            >::type type;
};

#ifdef _LIBCPP_STORE_AS_OPTIMIZATION

// __transform

template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};

#endif  // _LIBCPP_STORE_AS_OPTIMIZATION

// make_signed / make_unsigned

typedef
    __type_list<signed char,
    __type_list<signed short,
    __type_list<signed int,
    __type_list<signed long,
    __type_list<signed long long,
    __nat
    > > > > > __signed_types;

typedef
    __type_list<unsigned char,
    __type_list<unsigned short,
    __type_list<unsigned int,
    __type_list<unsigned long,
    __type_list<unsigned long long,
    __nat
    > > > > > __unsigned_types;

template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;

template <class _Hp, class _Tp, size_t _Size>
struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
{
    typedef _Hp type;
};

template <class _Hp, class _Tp, size_t _Size>
struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
{
    typedef typename __find_first<_Tp, _Size>::type type;
};

template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
                             bool = is_volatile<typename remove_reference<_Tp>::type>::value>
struct __apply_cv
{
    typedef _Up type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp, _Up, true, false>
{
    typedef const _Up type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp, _Up, false, true>
{
    typedef volatile _Up type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp, _Up, true, true>
{
    typedef const volatile _Up type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, false, false>
{
    typedef _Up& type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, true, false>
{
    typedef const _Up& type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, false, true>
{
    typedef volatile _Up& type;
};

template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, true, true>
{
    typedef const volatile _Up& type;
};

template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
struct __make_signed {};

template <class _Tp>
struct __make_signed<_Tp, true>
{
    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
};

template <> struct __make_signed<bool,               true> {};
template <> struct __make_signed<  signed short,     true> {typedef short     type;};
template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
template <> struct __make_signed<  signed int,       true> {typedef int       type;};
template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
template <> struct __make_signed<  signed long,      true> {typedef long      type;};
template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
template <> struct __make_signed<  signed long long, true> {typedef long long type;};
template <> struct __make_signed<unsigned long long, true> {typedef long long type;};

template <class _Tp>
struct make_signed
{
    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
};

template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
struct __make_unsigned {};

template <class _Tp>
struct __make_unsigned<_Tp, true>
{
    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
};

template <> struct __make_unsigned<bool,               true> {};
template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};

template <class _Tp>
struct make_unsigned
{
    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
};

#ifdef _LIBCPP_HAS_NO_VARIADICS

template <class _Tp, class _Up = void, class V = void>
struct common_type
{
public:
    typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
};


template <class _Tp>
struct common_type<_Tp, void, void>
{
public:
    typedef _Tp type;
};

template <class _Tp, class _Up>
struct common_type<_Tp, _Up, void>
{
private:
#ifdef _LIBCPP_MOVE
    static _Tp&& __t();
    static _Up&& __u();
#else
    static _Tp __t();
    static _Up __u();
    static bool __f();
#endif
public:
    typedef __typeof__(__f() ? __t() : __u()) type;
};

#else

template <class ..._Tp> struct common_type;

template <class _Tp>
struct common_type<_Tp>
{
    typedef _Tp type;
};

template <class _Tp, class _Up>
struct common_type<_Tp, _Up>
{
private:
    static _Tp&& __t();
    static _Up&& __u();
    static bool __f();
public:
    typedef decltype(__f() ? __t() : __u()) type;
};

template <class _Tp, class _Up, class ..._Vp>
struct common_type<_Tp, _Up, _Vp...>
{
    typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
};

#endif

// move

#ifdef _LIBCPP_MOVE

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename remove_reference<_Tp>::type&&
move(_Tp&& __t) {return __t;}

template <class _Tp, class _Up,
    class = typename _STD::enable_if<
         is_lvalue_reference<_Tp>::value ? is_lvalue_reference<_Up>::value : true
                     >::type,
    class = typename _STD::enable_if<
         is_convertible<typename remove_reference<_Up>::type*,
                        typename remove_reference<_Tp>::type*>::value>::type>
inline _LIBCPP_INLINE_VISIBILITY
_Tp&&
forward(_Up&& __t)
{
    return __t;  // to quiet spurious warning
//    return static_cast<_Tp&&>(__t);
}

#else  // _LIBCPP_MOVE

template <class T>
class __rv
{
    typedef typename remove_reference<T>::type Trr;
    Trr& t_;
public:
    Trr* operator->() {return &t_;}
    explicit __rv(Trr& t) : t_(t) {}
};

template <class T>
inline
typename enable_if
<
    !is_convertible<T, __rv<T> >::value,
    T&
>::type
move(T& t)
{
    return t;
}

template <class T>
inline
typename enable_if
<
    is_convertible<T, __rv<T> >::value,
    T
>::type
move(T& t)
{
    return T(__rv<T>(t));
}

template <class T, class U>
inline
typename enable_if
<
    !is_convertible<T, __rv<T> >::value,
    typename add_lvalue_reference<T>::type
>::type
forward(U& t)
{
    return t;
}

template <class T, class U>
inline
typename enable_if
<
    !is_convertible<T, __rv<T> >::value,
    typename add_lvalue_reference<T>::type
>::type
forward(const U& t)
{
    return t;
}

template <class T, class U>
inline
typename enable_if
<
    is_convertible<T, __rv<T> >::value,
    T
>::type
forward(U& t)
{
    return T(__rv<T>(t));
}

template <class T, class U>
inline
typename enable_if
<
    is_convertible<T, __rv<T> >::value,
    T
>::type
forward(const U& t)
{
    return T(__rv<T>(t));
}

#endif  // _LIBCPP_MOVE

#ifdef _LIBCPP_MOVE

template <class _Tp>
typename add_rvalue_reference<_Tp>::type
declval();

#else

template <class _Tp>
typename add_lvalue_reference<_Tp>::type
declval();

#endif

template <class _Tp>
struct decay
{
private:
    typedef typename remove_reference<_Tp>::type _Up;
public:
    typedef typename conditional
                     <
                         is_array<_Up>::value,
                         typename remove_extent<_Up>::type*,
                         typename conditional
                         <
                              is_function<_Up>::value,
                              typename add_pointer<_Up>::type,
                              typename remove_cv<_Up>::type
                         >::type
                     >::type type;
};

// result_of

template <class> class result_of;

template <class _Fn, bool>
class __result_of
{
};

#ifndef _LIBCPP_HAS_NO_VARIADICS

template <class _Fn, class ..._ArgTypes>
class __result_of<_Fn(_ArgTypes...), true>
{
public:
    typedef decltype(declval<_Fn>()(declval<_ArgTypes>()...)) type;
};

template <class _Fn, class ..._ArgTypes>
class result_of<_Fn(_ArgTypes...)>
    : public __result_of<_Fn(_ArgTypes...),
                         is_class<typename remove_reference<_Fn>::type>::value ||
                         is_function<typename remove_pointer<
                                        typename remove_reference<_Fn>::type
                                                            >::type
                                    >::value
                        >
{
};

#else

template <class _Fn>
class __result_of<_Fn(), true>
{
public:
    typedef decltype(declval<_Fn>()()) type;
};

template <class _Fn, class _A0>
class __result_of<_Fn(_A0), true>
{
public:
    typedef decltype(declval<_Fn>()(declval<_A0>())) type;
};

template <class _Fn, class _A0, class _A1>
class __result_of<_Fn(_A0, _A1), true>
{
public:
    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
};

template <class _Fn, class _A0, class _A1, class _A2>
class __result_of<_Fn(_A0, _A1, _A2), true>
{
public:
    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
};

template <class _Fn>
class result_of<_Fn()>
    : public __result_of<_Fn(),
                         is_class<typename remove_reference<_Fn>::type>::value ||
                         is_function<typename remove_pointer<
                                        typename remove_reference<_Fn>::type
                                                            >::type
                                    >::value
                        >
{
};

template <class _Fn, class _A0>
class result_of<_Fn(_A0)>
    : public __result_of<_Fn(_A0),
                         is_class<typename remove_reference<_Fn>::type>::value ||
                         is_function<typename remove_pointer<
                                        typename remove_reference<_Fn>::type
                                                            >::type
                                    >::value
                        >
{
};

template <class _Fn, class _A0, class _A1>
class result_of<_Fn(_A0, _A1)>
    : public __result_of<_Fn(_A0, _A1),
                         is_class<typename remove_reference<_Fn>::type>::value ||
                         is_function<typename remove_pointer<
                                        typename remove_reference<_Fn>::type
                                                            >::type
                                    >::value
                        >
{
};

template <class _Fn, class _A0, class _A1, class _A2>
class result_of<_Fn(_A0, _A1, _A2)>
    : public __result_of<_Fn(_A0, _A1, _A2),
                         is_class<typename remove_reference<_Fn>::type>::value ||
                         is_function<typename remove_pointer<
                                        typename remove_reference<_Fn>::type
                                                            >::type
                                    >::value
                        >
{
};

#endif

#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE

// template <class T, class... Args> struct is_constructible;

//      main is_constructible test

template <class _Tp, class ..._Args>
decltype(_STD::move(_Tp(_STD::declval<_Args>()...)), true_type())
__is_constructible_test(_Tp&&, _Args&& ...);

struct __any
{
    __any(...);
};

template <class ..._Args>
false_type
__is_constructible_test(__any, _Args&& ...);

template <bool, class _Tp, class... _Args>
struct __is_constructible // false, _Tp is not a scalar
    : public common_type
             <
                 decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
             >::type
    {};

//      function types are not constructible

template <class _R, class... _A1, class... _A2>
struct __is_constructible<false, _R(_A1...), _A2...>
    : public false_type
    {};

//      handle scalars and reference types

//      Scalars are default constructible, references are not

template <class _Tp>
struct __is_constructible<true, _Tp> 
    : public is_scalar<_Tp>
    {};

//      Scalars and references are constructible from one arg if that arg is
//          implicitly convertible to the scalar or reference.

template <class _Tp>
struct __is_constructible_ref
{
    true_type static __(_Tp);
    false_type static __(...);
};

template <class _Tp, class _A0>
struct __is_constructible<true, _Tp, _A0> 
    : public common_type
             <
                 decltype(__is_constructible_ref<_Tp>::__(declval<_A0>()))
             >::type
    {};

//      Scalars and references are not constructible from multiple args.

template <class _Tp, class _A0, class ..._Args>
struct __is_constructible<true, _Tp, _A0, _Args...> 
    : public false_type
    {};

//      Treat scalars and reference types separately

template <bool, class _Tp, class... _Args>
struct __is_constructible_void_check
    : public __is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
                                _Tp, _Args...>
    {};

//      If any of T or Args is void, is_constructible should be false

template <class _Tp, class... _Args>
struct __is_constructible_void_check<true, _Tp, _Args...>
    : public false_type
    {};

template <class ..._Args> struct __constains_void;

template <> struct __constains_void<> : false_type {};

template <class _A0, class ..._Args>
struct __constains_void<_A0, _Args...>
{
    static const bool value = is_void<_A0>::value ||
                              __constains_void<_Args...>::value;
};

//      is_constructible entry point

template <class _Tp, class... _Args>
struct is_constructible
    : public __is_constructible_void_check<__constains_void<_Tp, _Args...>::value,
                                           _Tp, _Args...>
    {};

//      Array types are default constructible if their element type
//      is default constructible

template <class _A, size_t _N>
struct __is_constructible<false, _A[_N]>
    : public is_constructible<typename remove_all_extents<_A>::type>
    {};

//      Otherwise array types are not constructible by this syntax

template <class _A, size_t _N, class ..._Args>
struct __is_constructible<false, _A[_N], _Args...>
    : public false_type
    {};

//      Incomplete array types are not constructible

template <class _A, class ..._Args>
struct __is_constructible<false, _A[], _Args...>
    : public false_type
    {};

#endif

template <class _Tp> struct __is_zero_default_constructible
    : public integral_constant<bool, is_scalar<_Tp>::value || is_empty<_Tp>::value> {};

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(_Tp& __x, _Tp& __y)
{
    _Tp __t(_STD::move(__x));
    __x = _STD::move(__y);
    __y = _STD::move(__t);
}

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP_TYPE_TRAITS