-
Notifications
You must be signed in to change notification settings - Fork 27
/
type_traits
3774 lines (3121 loc) · 111 KB
/
type_traits
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
// C++11 <type_traits> -*- 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/type_traits
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_TYPE_TRAITS
#define _GLIBCXX_TYPE_TRAITS 1
#pragma GCC system_header
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
#include <bits/c++config.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @defgroup metaprogramming Metaprogramming
* @ingroup utilities
*
* Template utilities for compile-time introspection and modification,
* including type classification traits, type property inspection traits
* and type transformation traits.
*
* @{
*/
/// integral_constant
template<typename _Tp, _Tp __v>
struct integral_constant
{
static constexpr _Tp value = __v;
typedef _Tp value_type;
typedef integral_constant<_Tp, __v> type;
constexpr operator value_type() const noexcept { return value; }
#if __cplusplus > 201103L
#define __cpp_lib_integral_constant_callable 201304
constexpr value_type operator()() const noexcept { return value; }
#endif
};
template<typename _Tp, _Tp __v>
constexpr _Tp integral_constant<_Tp, __v>::value;
/// The type used as a compile-time boolean with true value.
typedef integral_constant<bool, true> true_type;
/// The type used as a compile-time boolean with false value.
typedef integral_constant<bool, false> false_type;
template<bool __v>
using __bool_constant = integral_constant<bool, __v>;
#if __cplusplus > 201402L
# define __cpp_lib_bool_constant 201505
template<bool __v>
using bool_constant = integral_constant<bool, __v>;
#endif
// Meta programming helper types.
template<bool, typename, typename>
struct conditional;
template <typename _Type>
struct __type_identity
{ using type = _Type; };
template<typename _Tp>
using __type_identity_t = typename __type_identity<_Tp>::type;
template<typename...>
struct __or_;
template<>
struct __or_<>
: public false_type
{ };
template<typename _B1>
struct __or_<_B1>
: public _B1
{ };
template<typename _B1, typename _B2>
struct __or_<_B1, _B2>
: public conditional<_B1::value, _B1, _B2>::type
{ };
template<typename _B1, typename _B2, typename _B3, typename... _Bn>
struct __or_<_B1, _B2, _B3, _Bn...>
: public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
{ };
template<typename...>
struct __and_;
template<>
struct __and_<>
: public true_type
{ };
template<typename _B1>
struct __and_<_B1>
: public _B1
{ };
template<typename _B1, typename _B2>
struct __and_<_B1, _B2>
: public conditional<_B1::value, _B2, _B1>::type
{ };
template<typename _B1, typename _B2, typename _B3, typename... _Bn>
struct __and_<_B1, _B2, _B3, _Bn...>
: public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
{ };
template<typename _Pp>
struct __not_
: public __bool_constant<!bool(_Pp::value)>
{ };
#if __cplusplus >= 201703L
template<typename... _Bn>
inline constexpr bool __or_v = __or_<_Bn...>::value;
template<typename... _Bn>
inline constexpr bool __and_v = __and_<_Bn...>::value;
#define __cpp_lib_logical_traits 201510
template<typename... _Bn>
struct conjunction
: __and_<_Bn...>
{ };
template<typename... _Bn>
struct disjunction
: __or_<_Bn...>
{ };
template<typename _Pp>
struct negation
: __not_<_Pp>
{ };
template<typename... _Bn>
inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
template<typename... _Bn>
inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
template<typename _Pp>
inline constexpr bool negation_v = negation<_Pp>::value;
#endif // C++17
// Forward declarations
template<typename>
struct is_reference;
template<typename>
struct is_function;
template<typename>
struct is_void;
template<typename>
struct __is_array_unknown_bounds;
// Helper functions that return false_type for incomplete classes,
// incomplete unions and arrays of known bound from those.
template <typename _Tp, size_t = sizeof(_Tp)>
constexpr true_type __is_complete_or_unbounded(__type_identity<_Tp>)
{ return {}; }
template <typename _TypeIdentity,
typename _NestedType = typename _TypeIdentity::type>
constexpr typename __or_<
is_reference<_NestedType>,
is_function<_NestedType>,
is_void<_NestedType>,
__is_array_unknown_bounds<_NestedType>
>::type __is_complete_or_unbounded(_TypeIdentity)
{ return {}; }
// For several sfinae-friendly trait implementations we transport both the
// result information (as the member type) and the failure information (no
// member type). This is very similar to std::enable_if, but we cannot use
// them, because we need to derive from them as an implementation detail.
template<typename _Tp>
struct __success_type
{ typedef _Tp type; };
struct __failure_type
{ };
template<typename>
struct remove_cv;
// __remove_cv_t (std::remove_cv_t for C++11).
template<typename _Tp>
using __remove_cv_t = typename remove_cv<_Tp>::type;
template<typename>
struct is_const;
// Primary type categories.
template<typename>
struct __is_void_helper
: public false_type { };
template<>
struct __is_void_helper<void>
: public true_type { };
/// is_void
template<typename _Tp>
struct is_void
: public __is_void_helper<__remove_cv_t<_Tp>>::type
{ };
template<typename>
struct __is_integral_helper
: public false_type { };
template<>
struct __is_integral_helper<bool>
: public true_type { };
template<>
struct __is_integral_helper<char>
: public true_type { };
template<>
struct __is_integral_helper<signed char>
: public true_type { };
template<>
struct __is_integral_helper<unsigned char>
: public true_type { };
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
struct __is_integral_helper<wchar_t>
: public true_type { };
#endif
#ifdef _GLIBCXX_USE_CHAR8_T
template<>
struct __is_integral_helper<char8_t>
: public true_type { };
#endif
template<>
struct __is_integral_helper<char16_t>
: public true_type { };
template<>
struct __is_integral_helper<char32_t>
: public true_type { };
template<>
struct __is_integral_helper<short>
: public true_type { };
template<>
struct __is_integral_helper<unsigned short>
: public true_type { };
template<>
struct __is_integral_helper<int>
: public true_type { };
template<>
struct __is_integral_helper<unsigned int>
: public true_type { };
template<>
struct __is_integral_helper<long>
: public true_type { };
template<>
struct __is_integral_helper<unsigned long>
: public true_type { };
template<>
struct __is_integral_helper<long long>
: public true_type { };
template<>
struct __is_integral_helper<unsigned long long>
: public true_type { };
// Conditionalizing on __STRICT_ANSI__ here will break any port that
// uses one of these types for size_t.
#if defined(__GLIBCXX_TYPE_INT_N_0)
template<>
struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
: public true_type { };
template<>
struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
: public true_type { };
#endif
#if defined(__GLIBCXX_TYPE_INT_N_1)
template<>
struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
: public true_type { };
template<>
struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
: public true_type { };
#endif
#if defined(__GLIBCXX_TYPE_INT_N_2)
template<>
struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
: public true_type { };
template<>
struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
: public true_type { };
#endif
#if defined(__GLIBCXX_TYPE_INT_N_3)
template<>
struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
: public true_type { };
template<>
struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
: public true_type { };
#endif
/// is_integral
template<typename _Tp>
struct is_integral
: public __is_integral_helper<__remove_cv_t<_Tp>>::type
{ };
template<typename>
struct __is_floating_point_helper
: public false_type { };
template<>
struct __is_floating_point_helper<float>
: public true_type { };
template<>
struct __is_floating_point_helper<double>
: public true_type { };
template<>
struct __is_floating_point_helper<long double>
: public true_type { };
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
template<>
struct __is_floating_point_helper<__float128>
: public true_type { };
#endif
/// is_floating_point
template<typename _Tp>
struct is_floating_point
: public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
{ };
/// is_array
template<typename>
struct is_array
: public false_type { };
template<typename _Tp, std::size_t _Size>
struct is_array<_Tp[_Size]>
: public true_type { };
template<typename _Tp>
struct is_array<_Tp[]>
: public true_type { };
template<typename>
struct __is_pointer_helper
: public false_type { };
template<typename _Tp>
struct __is_pointer_helper<_Tp*>
: public true_type { };
/// is_pointer
template<typename _Tp>
struct is_pointer
: public __is_pointer_helper<__remove_cv_t<_Tp>>::type
{ };
/// is_lvalue_reference
template<typename>
struct is_lvalue_reference
: public false_type { };
template<typename _Tp>
struct is_lvalue_reference<_Tp&>
: public true_type { };
/// is_rvalue_reference
template<typename>
struct is_rvalue_reference
: public false_type { };
template<typename _Tp>
struct is_rvalue_reference<_Tp&&>
: public true_type { };
template<typename>
struct __is_member_object_pointer_helper
: public false_type { };
template<typename _Tp, typename _Cp>
struct __is_member_object_pointer_helper<_Tp _Cp::*>
: public __not_<is_function<_Tp>>::type { };
/// is_member_object_pointer
template<typename _Tp>
struct is_member_object_pointer
: public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
{ };
template<typename>
struct __is_member_function_pointer_helper
: public false_type { };
template<typename _Tp, typename _Cp>
struct __is_member_function_pointer_helper<_Tp _Cp::*>
: public is_function<_Tp>::type { };
/// is_member_function_pointer
template<typename _Tp>
struct is_member_function_pointer
: public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
{ };
/// is_enum
template<typename _Tp>
struct is_enum
: public integral_constant<bool, __is_enum(_Tp)>
{ };
/// is_union
template<typename _Tp>
struct is_union
: public integral_constant<bool, __is_union(_Tp)>
{ };
/// is_class
template<typename _Tp>
struct is_class
: public integral_constant<bool, __is_class(_Tp)>
{ };
/// is_function
template<typename _Tp>
struct is_function
: public __bool_constant<!is_const<const _Tp>::value> { };
template<typename _Tp>
struct is_function<_Tp&>
: public false_type { };
template<typename _Tp>
struct is_function<_Tp&&>
: public false_type { };
#define __cpp_lib_is_null_pointer 201309
template<typename>
struct __is_null_pointer_helper
: public false_type { };
template<>
struct __is_null_pointer_helper<std::nullptr_t>
: public true_type { };
/// is_null_pointer (LWG 2247).
template<typename _Tp>
struct is_null_pointer
: public __is_null_pointer_helper<__remove_cv_t<_Tp>>::type
{ };
/// __is_nullptr_t (deprecated extension).
template<typename _Tp>
struct __is_nullptr_t
: public is_null_pointer<_Tp>
{ } _GLIBCXX_DEPRECATED_SUGGEST("std::is_null_pointer");
// Composite type categories.
/// is_reference
template<typename _Tp>
struct is_reference
: public __or_<is_lvalue_reference<_Tp>,
is_rvalue_reference<_Tp>>::type
{ };
/// is_arithmetic
template<typename _Tp>
struct is_arithmetic
: public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
{ };
/// is_fundamental
template<typename _Tp>
struct is_fundamental
: public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
is_null_pointer<_Tp>>::type
{ };
/// is_object
template<typename _Tp>
struct is_object
: public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
is_void<_Tp>>>::type
{ };
template<typename>
struct is_member_pointer;
/// is_scalar
template<typename _Tp>
struct is_scalar
: public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
{ };
/// is_compound
template<typename _Tp>
struct is_compound
: public __not_<is_fundamental<_Tp>>::type { };
template<typename _Tp>
struct __is_member_pointer_helper
: public false_type { };
template<typename _Tp, typename _Cp>
struct __is_member_pointer_helper<_Tp _Cp::*>
: public true_type { };
/// is_member_pointer
template<typename _Tp>
struct is_member_pointer
: public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type
{ };
template<typename, typename>
struct is_same;
template<typename _Tp, typename... _Types>
using __is_one_of = __or_<is_same<_Tp, _Types>...>;
// Check if a type is one of the signed integer types.
template<typename _Tp>
using __is_signed_integer = __is_one_of<__remove_cv_t<_Tp>,
signed char, signed short, signed int, signed long,
signed long long
#if defined(__GLIBCXX_TYPE_INT_N_0)
, signed __GLIBCXX_TYPE_INT_N_0
#endif
#if defined(__GLIBCXX_TYPE_INT_N_1)
, signed __GLIBCXX_TYPE_INT_N_1
#endif
#if defined(__GLIBCXX_TYPE_INT_N_2)
, signed __GLIBCXX_TYPE_INT_N_2
#endif
#if defined(__GLIBCXX_TYPE_INT_N_3)
, signed __GLIBCXX_TYPE_INT_N_3
#endif
>;
// Check if a type is one of the unsigned integer types.
template<typename _Tp>
using __is_unsigned_integer = __is_one_of<__remove_cv_t<_Tp>,
unsigned char, unsigned short, unsigned int, unsigned long,
unsigned long long
#if defined(__GLIBCXX_TYPE_INT_N_0)
, unsigned __GLIBCXX_TYPE_INT_N_0
#endif
#if defined(__GLIBCXX_TYPE_INT_N_1)
, unsigned __GLIBCXX_TYPE_INT_N_1
#endif
#if defined(__GLIBCXX_TYPE_INT_N_2)
, unsigned __GLIBCXX_TYPE_INT_N_2
#endif
#if defined(__GLIBCXX_TYPE_INT_N_3)
, unsigned __GLIBCXX_TYPE_INT_N_3
#endif
>;
// Check if a type is one of the signed or unsigned integer types.
template<typename _Tp>
using __is_standard_integer
= __or_<__is_signed_integer<_Tp>, __is_unsigned_integer<_Tp>>;
// __void_t (std::void_t for C++11)
template<typename...> using __void_t = void;
// Utility to detect referenceable types ([defns.referenceable]).
template<typename _Tp, typename = void>
struct __is_referenceable
: public false_type
{ };
template<typename _Tp>
struct __is_referenceable<_Tp, __void_t<_Tp&>>
: public true_type
{ };
// Type properties.
/// is_const
template<typename>
struct is_const
: public false_type { };
template<typename _Tp>
struct is_const<_Tp const>
: public true_type { };
/// is_volatile
template<typename>
struct is_volatile
: public false_type { };
template<typename _Tp>
struct is_volatile<_Tp volatile>
: public true_type { };
/// is_trivial
template<typename _Tp>
struct is_trivial
: public integral_constant<bool, __is_trivial(_Tp)>
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
// is_trivially_copyable
template<typename _Tp>
struct is_trivially_copyable
: public integral_constant<bool, __is_trivially_copyable(_Tp)>
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
/// is_standard_layout
template<typename _Tp>
struct is_standard_layout
: public integral_constant<bool, __is_standard_layout(_Tp)>
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
/// is_pod (deprecated in C++20)
// Could use is_standard_layout && is_trivial instead of the builtin.
template<typename _Tp>
struct
_GLIBCXX20_DEPRECATED("use is_standard_layout && is_trivial instead")
is_pod
: public integral_constant<bool, __is_pod(_Tp)>
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
/// is_literal_type
template<typename _Tp>
struct is_literal_type
: public integral_constant<bool, __is_literal_type(_Tp)>
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
/// is_empty
template<typename _Tp>
struct is_empty
: public integral_constant<bool, __is_empty(_Tp)>
{ };
/// is_polymorphic
template<typename _Tp>
struct is_polymorphic
: public integral_constant<bool, __is_polymorphic(_Tp)>
{ };
#if __cplusplus >= 201402L
#define __cpp_lib_is_final 201402L
/// is_final
template<typename _Tp>
struct is_final
: public integral_constant<bool, __is_final(_Tp)>
{ };
#endif
/// is_abstract
template<typename _Tp>
struct is_abstract
: public integral_constant<bool, __is_abstract(_Tp)>
{ };
template<typename _Tp,
bool = is_arithmetic<_Tp>::value>
struct __is_signed_helper
: public false_type { };
template<typename _Tp>
struct __is_signed_helper<_Tp, true>
: public integral_constant<bool, _Tp(-1) < _Tp(0)>
{ };
/// is_signed
template<typename _Tp>
struct is_signed
: public __is_signed_helper<_Tp>::type
{ };
/// is_unsigned
template<typename _Tp>
struct is_unsigned
: public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>
{ };
// Destructible and constructible type properties.
/**
* @brief Utility to simplify expressions used in unevaluated operands
* @ingroup utilities
*/
template<typename _Tp, typename _Up = _Tp&&>
_Up
__declval(int);
template<typename _Tp>
_Tp
__declval(long);
template<typename _Tp>
auto declval() noexcept -> decltype(__declval<_Tp>(0));
template<typename, unsigned = 0>
struct extent;
template<typename>
struct remove_all_extents;
template<typename _Tp>
struct __is_array_known_bounds
: public integral_constant<bool, (extent<_Tp>::value > 0)>
{ };
template<typename _Tp>
struct __is_array_unknown_bounds
: public __and_<is_array<_Tp>, __not_<extent<_Tp>>>
{ };
// In N3290 is_destructible does not say anything about function
// types and abstract types, see LWG 2049. This implementation
// describes function types as non-destructible and all complete
// object types as destructible, iff the explicit destructor
// call expression is wellformed.
struct __do_is_destructible_impl
{
template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
static true_type __test(int);
template<typename>
static false_type __test(...);
};
template<typename _Tp>
struct __is_destructible_impl
: public __do_is_destructible_impl
{
typedef decltype(__test<_Tp>(0)) type;
};
template<typename _Tp,
bool = __or_<is_void<_Tp>,
__is_array_unknown_bounds<_Tp>,
is_function<_Tp>>::value,
bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
struct __is_destructible_safe;
template<typename _Tp>
struct __is_destructible_safe<_Tp, false, false>
: public __is_destructible_impl<typename
remove_all_extents<_Tp>::type>::type
{ };
template<typename _Tp>
struct __is_destructible_safe<_Tp, true, false>
: public false_type { };
template<typename _Tp>
struct __is_destructible_safe<_Tp, false, true>
: public true_type { };
/// is_destructible
template<typename _Tp>
struct is_destructible
: public __is_destructible_safe<_Tp>::type
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
// is_nothrow_destructible requires that is_destructible is
// satisfied as well. We realize that by mimicing the
// implementation of is_destructible but refer to noexcept(expr)
// instead of decltype(expr).
struct __do_is_nt_destructible_impl
{
template<typename _Tp>
static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
__test(int);
template<typename>
static false_type __test(...);
};
template<typename _Tp>
struct __is_nt_destructible_impl
: public __do_is_nt_destructible_impl
{
typedef decltype(__test<_Tp>(0)) type;
};
template<typename _Tp,
bool = __or_<is_void<_Tp>,
__is_array_unknown_bounds<_Tp>,
is_function<_Tp>>::value,
bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
struct __is_nt_destructible_safe;
template<typename _Tp>
struct __is_nt_destructible_safe<_Tp, false, false>
: public __is_nt_destructible_impl<typename
remove_all_extents<_Tp>::type>::type
{ };
template<typename _Tp>
struct __is_nt_destructible_safe<_Tp, true, false>
: public false_type { };
template<typename _Tp>
struct __is_nt_destructible_safe<_Tp, false, true>
: public true_type { };
/// is_nothrow_destructible
template<typename _Tp>
struct is_nothrow_destructible
: public __is_nt_destructible_safe<_Tp>::type
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
"template argument must be a complete class or an unbounded array");
};
#if __GNUC__ >= 8
template<typename _Tp, typename... _Args>
struct __is_constructible_impl
: public __bool_constant<__is_constructible(_Tp, _Args...)>
{ };
#else
// Implementation of __is_constructible_impl.
struct __do_is_default_constructible_impl
{
template<typename _Tp, typename = decltype(_Tp())>
static true_type __test(int);
template<typename>
static false_type __test(...);
};
template<typename _Tp>
struct __is_default_constructible_impl
: public __do_is_default_constructible_impl
{
typedef decltype(__test<_Tp>(0)) type;
};
template<typename _Tp>
struct __is_default_constructible_atom
: public __and_<__not_<is_void<_Tp>>,
__is_default_constructible_impl<_Tp>>::type
{ };
template<typename _Tp, bool = is_array<_Tp>::value>
struct __is_default_constructible_safe;
// The following technique is a workaround for a current core language
// restriction, which does not allow for array types to occur in
// functional casts of the form T(). Complete arrays can be default-
// constructed, if the element type is default-constructible, but
// arrays with unknown bounds are not.
template<typename _Tp>
struct __is_default_constructible_safe<_Tp, true>
: public __and_<__is_array_known_bounds<_Tp>,
__is_default_constructible_atom<typename
remove_all_extents<_Tp>::type>>::type
{ };
template<typename _Tp>
struct __is_default_constructible_safe<_Tp, false>
: public __is_default_constructible_atom<_Tp>::type
{ };
// The hardest part of this trait is the binary direct-initialization
// case, because we hit into a functional cast of the form T(arg).
// This implementation uses different strategies depending on the
// target type to reduce the test overhead as much as possible:
//
// a) For a reference target type, we use a static_cast expression
// modulo its extra cases.
//
// b) For a non-reference target type we use a ::new expression.
struct __do_is_static_castable_impl
{
template<typename _From, typename _To, typename
= decltype(static_cast<_To>(declval<_From>()))>
static true_type __test(int);
template<typename, typename>
static false_type __test(...);
};
template<typename _From, typename _To>
struct __is_static_castable_impl
: public __do_is_static_castable_impl
{
typedef decltype(__test<_From, _To>(0)) type;
};
template<typename _From, typename _To>
struct __is_static_castable_safe
: public __is_static_castable_impl<_From, _To>::type
{ };
// __is_static_castable
template<typename _From, typename _To>
struct __is_static_castable
: public integral_constant<bool, (__is_static_castable_safe<
_From, _To>::value)>
{ };
// Implementation for non-reference types. To meet the proper
// variable definition semantics, we also need to test for
// is_destructible in this case.
// This form should be simplified by a single expression:
// ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
struct __do_is_direct_constructible_impl
{
template<typename _Tp, typename _Arg, typename
= decltype(::new _Tp(declval<_Arg>()))>
static true_type __test(int);
template<typename, typename>
static false_type __test(...);
};