forked from SGSSGene/StandardCplusplus
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtype_traits
1333 lines (1099 loc) · 31.7 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
/* Copyright (C) 2005 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __HEADER_TYPE_TRAITS
#define __HEADER_TYPE_TRAITS 1
#include <basic_definitions>
#include <char_traits>
#include <cstddef>
#include <exception>
#include <memory>
#include <string.h>
#include <utility>
#include <bits/reference_transformations.hpp>
#include <bits/type_traits_impl.hpp>
#pragma GCC visibility push(default)
namespace std
{
template <class T>
class reference_wrapper; // defined in <functional>
template <typename, unsigned = 0>
struct extent;
template <typename>
struct remove_all_extents;
template <bool _Cond, typename _Iftrue, typename _Iffalse>
struct conditional;
template<bool Bool, class TrueType, class FalseType>
using conditional_t = typename conditional<Bool,TrueType,FalseType>::type;
template <typename T>
struct add_rvalue_reference;
template <typename T>
struct add_lvalue_reference;
template< class T >
struct add_pointer;
template< class T >
struct remove_extent;
template <typename>
struct is_function;
template <typename T>
struct is_member_object_pointer;
template <typename T>
struct is_member_function_pointer;
template< class T >
struct is_member_pointer;
template <typename T>
struct is_default_constructible;
template <typename T>
struct is_array;
template<class Base, class Derived>
struct is_base_of;
struct __sfinae_types
{
typedef char __one;
typedef struct
{
char __arr[2];
} __two;
};
// Define a nested type if some predicate holds.
// Primary template.
/// enable_if
template <bool, typename _Tp = void>
struct enable_if
{
};
// Partial specialization for true.
template <typename _Tp>
struct enable_if<true, _Tp>
{
typedef _Tp type;
};
template <bool Cond, typename T = void>
using enable_if_t = enable_if<Cond, T>;
/// add_const
template <typename _Tp>
struct add_const
{
typedef _Tp const type;
};
/// add_volatile
template <typename _Tp>
struct add_volatile
{
typedef _Tp volatile type;
};
/// add_cv
template <typename _Tp>
struct add_cv
{
typedef typename add_const<typename add_volatile<_Tp>::type>::type type;
};
/// remove extent
template<class T>
struct remove_extent { typedef T type; };
template<class T>
struct remove_extent<T[]> { typedef T type; };
template<class T, size_t N>
struct remove_extent<T[N]> { typedef T type; };
/// decay
template< class T >
struct decay {
private:
typedef typename remove_reference<T>::type U;
public:
typedef typename conditional<
is_array<U>::value,
typename remove_extent<U>::type*,
typename conditional<
is_function<U>::value,
typename add_pointer<U>::type,
typename remove_cv<U>::type
>::type
>::type type;
};
template< class T >
using decay_t = typename decay<T>::type;
/// declval
template <typename _Tp>
struct __declval_protector
{
static const bool __stop = false;
static typename add_rvalue_reference<_Tp>::type __delegate();
};
template <typename _Tp>
inline typename add_rvalue_reference<_Tp>::type
declval() noexcept
{
static_assert(__declval_protector<_Tp>::__stop,
"declval() must not be used!");
return __declval_protector<_Tp>::__delegate();
}
/// result_of
template <typename _Signature>
class result_of;
namespace detail {
template <class T>
struct is_reference_wrapper : false_type {};
template <class U>
struct is_reference_wrapper<reference_wrapper<U>> : true_type {};
template <class Base, class T, class Derived, class... Args>
auto INVOKE(T Base::*pmf, Derived&& ref, Args&&... args)
-> typename enable_if<is_function<T>::value &&
is_base_of<Base, typename decay<Derived>::type>::value,
decltype((forward<Derived>(ref).*pmf)(forward<Args>(args)...))>::type;
template <class Base, class T, class RefWrap, class... Args>
auto INVOKE(T Base::*pmf, RefWrap&& ref, Args&&... args)
-> typename enable_if<is_function<T>::value &&
is_reference_wrapper<typename decay<RefWrap>::type>::value,
decltype((ref.get().*pmf)(forward<Args>(args)...))>::type;
template <class Base, class T, class Pointer, class... Args>
auto INVOKE(T Base::*pmf, Pointer&& ptr, Args&&... args)
-> typename enable_if<is_function<T>::value &&
!is_reference_wrapper<typename decay<Pointer>::type>::value &&
!is_base_of<Base, typename decay<Pointer>::type>::value,
decltype(((*forward<Pointer>(ptr)).*pmf)(forward<Args>(args)...))>::type;
template <class Base, class T, class Derived>
auto INVOKE(T Base::*pmd, Derived&& ref)
-> typename enable_if<!is_function<T>::value &&
is_base_of<Base, typename decay<Derived>::type>::value,
decltype(forward<Derived>(ref).*pmd)>::type;
template <class Base, class T, class RefWrap>
auto INVOKE(T Base::*pmd, RefWrap&& ref)
-> typename enable_if<!is_function<T>::value &&
is_reference_wrapper<typename decay<RefWrap>::type>::value,
decltype(ref.get().*pmd)>::type;
template <class Base, class T, class Pointer>
auto INVOKE(T Base::*pmd, Pointer&& ptr)
-> typename enable_if<!is_function<T>::value &&
!is_reference_wrapper<typename decay<Pointer>::type>::value &&
!is_base_of<Base, typename decay<Pointer>::type>::value,
decltype((*forward<Pointer>(ptr)).*pmd)>::type;
template <class Func, class... Args>
auto INVOKE(Func&& f, Args&&... args)
-> typename enable_if<!is_member_pointer<typename decay<Func>::type>::value,
decltype(forward<Func>(f)(forward<Args>(args)...))>::type;
} // namespace detail
// Minimal C++11 implementation:
template <class> struct result_of;
template <class Func, class... ArgTypes>
struct result_of<Func(ArgTypes...)> {
using type = decltype(detail::INVOKE(declval<Func>(), declval<ArgTypes>()...));
};
template< class T >
using result_of_t = typename result_of<T>::type;
///Invoke result
// Conforming C++14 implementation (is also a valid C++11 implementation):
namespace detail {
template <typename AlwaysVoid, typename, typename...>
struct invoke_result { };
template <typename Func, typename...Args>
struct invoke_result<decltype(void(detail::INVOKE(declval<Func>(), declval<Args>()...))),
Func, Args...> {
using type = decltype(detail::INVOKE(declval<Func>(), declval<Args>()...));
};
}
template <class Func, class... ArgTypes>
struct invoke_result : detail::invoke_result<void, Func, ArgTypes...> {};
template< class Func, class... ArgTypes>
using invoke_result_t = typename invoke_result<Func, ArgTypes...>::type;
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 integral_constant<bool, (__is_void_helper<typename remove_cv<_Tp>::type>::value)>
{
};
/// OR / AND / NOT helpers for std::conditional
template <typename, typename, typename...>
struct __or_;
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, typename, typename...>
struct __and_;
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 integral_constant<bool, !_Pp::value>
{
};
/// is_array
template <typename>
struct is_array
: public false_type
{
};
template <typename _Tp, size_t _Size>
struct is_array<_Tp[_Size]>
: public true_type
{
};
template <typename _Tp>
struct is_array<_Tp[]>
: public true_type
{
};
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>>>::type
{
};
/// extent
template <typename, unsigned _Uint>
struct extent
: public integral_constant<size_t, 0>
{
};
template <typename _Tp, unsigned _Uint, size_t _Size>
struct extent<_Tp[_Size], _Uint>
: public integral_constant<size_t,
_Uint == 0 ? _Size : extent<_Tp, _Uint - 1>::value>
{
};
template <typename _Tp, unsigned _Uint>
struct extent<_Tp[], _Uint>
: public integral_constant<size_t,
_Uint == 0 ? 0 : extent<_Tp, _Uint - 1>::value>
{
};
/// remove_all_extents
template <typename _Tp>
struct remove_all_extents
{
typedef _Tp type;
};
template <typename _Tp, size_t _Size>
struct remove_all_extents<_Tp[_Size]>
{
typedef typename remove_all_extents<_Tp>::type type;
};
template <typename _Tp>
struct remove_all_extents<_Tp[]>
{
typedef typename remove_all_extents<_Tp>::type type;
};
/// __is_nt_default_constructible
template <typename T>
struct __is_nt_default_constructible_atom
: public integral_constant<bool, noexcept(T())>
{
};
template <typename T, bool = is_array<T>::value>
struct __is_nt_default_constructible_impl;
template <typename T>
struct __is_nt_default_constructible_impl<T, true>
: public __and_<__is_array_known_bounds<T>,
__is_nt_default_constructible_atom<typename remove_all_extents<T>::type>>::type
{
};
template <typename T>
struct __is_nt_default_constructible_impl<T, false>
: public __is_nt_default_constructible_atom<T>
{
};
template <typename T>
struct is_union : public integral_constant<bool, __is_union(T)>
{
};
template <typename T>
struct is_class : public integral_constant<bool, __is_class(T)>
{
};
template <typename T>
struct is_empty : public integral_constant<bool, __is_empty(T)>
{
};
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 integral_constant<bool, (__is_pointer_helper<typename remove_cv<_Tp>::type>::value)>
{
};
/// is_function
template <typename>
struct is_function
: public false_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes...)>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes......)>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes...) const>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes......) const>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes...) volatile>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes......) volatile>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes...) const volatile>
: public true_type
{
};
template <typename _Res, typename... _ArgTypes>
struct is_function<_Res(_ArgTypes......) const volatile>
: public true_type
{
};
template <typename>
struct __is_nullptr_t_helper
: public false_type
{
};
template <>
struct __is_nullptr_t_helper<nullptr_t>
: public true_type
{
};
// __is_nullptr_t (extension).
template <typename _Tp>
struct __is_nullptr_t
: public integral_constant<bool, (__is_nullptr_t_helper<typename remove_cv<_Tp>::type>::value)>
{
};
/// is_member_object_pointer
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 integral_constant<bool, !is_function<_Tp>::value>
{
};
template <typename _Tp>
struct is_member_object_pointer
: public integral_constant<bool, (__is_member_object_pointer_helper<
typename remove_cv<_Tp>::type>::value)>
{
};
/// is_reference
template <typename _Tp>
struct is_reference
: public __or_<is_lvalue_reference<_Tp>,
is_rvalue_reference<_Tp>>::type
{
};
template <typename _Tp,
bool = __and_<__not_<is_reference<_Tp>>,
__not_<is_void<_Tp>>>::value,
bool = is_rvalue_reference<_Tp>::value>
struct __add_lvalue_reference_helper
{
typedef _Tp type;
};
template <typename _Tp>
struct __add_lvalue_reference_helper<_Tp, true, false>
{
typedef _Tp &type;
};
template <typename _Tp>
struct __add_lvalue_reference_helper<_Tp, false, true>
{
typedef typename remove_reference<_Tp>::type &type;
};
/// add_lvalue_reference
template <typename _Tp>
struct add_lvalue_reference
: public __add_lvalue_reference_helper<_Tp>
{
};
template <typename _Tp,
bool = __and_<__not_<is_reference<_Tp>>,
__not_<is_void<_Tp>>>::value>
struct __add_rvalue_reference_helper
{
typedef _Tp type;
};
template <typename _Tp>
struct __add_rvalue_reference_helper<_Tp, true>
{
typedef _Tp &&type;
};
/// add_rvalue_reference
template <typename _Tp>
struct add_rvalue_reference
: public __add_rvalue_reference_helper<_Tp>
{
};
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 integral_constant<bool, is_function<_Tp>::value>
{
};
/// is_member_pointer
template< class T >
struct is_member_pointer_helper : false_type {};
template< class T, class U >
struct is_member_pointer_helper<T U::*> : true_type {};
template< class T >
struct is_member_pointer :
is_member_pointer_helper<typename remove_cv<T>::type> {};
/// add_pointer
namespace detail {
template< class T, bool is_function_type = false >
struct add_pointer {
using type = typename remove_reference<T>::type*;
};
template< class T >
struct add_pointer<T, true> {
using type = T;
};
template< class T, class... Args >
struct add_pointer<T(Args...), true> {
using type = T(*)(Args...);
};
template< class T, class... Args >
struct add_pointer<T(Args..., ...), true> {
using type = T(*)(Args..., ...);
};
} // namespace detail
template< class T >
struct add_pointer : detail::add_pointer<T, is_function<T>::value> {};
/// is_member_function_pointer
template <typename _Tp>
struct is_member_function_pointer
: public integral_constant<bool, (__is_member_function_pointer_helper<
typename remove_cv<_Tp>::type>::value)>
{
};
/// is_base_of
namespace details {
template <typename Base> true_type is_base_of_test_func(const volatile Base*);
template <typename Base> false_type is_base_of_test_func(const volatile void*);
template <typename Base, typename Derived>
using pre_is_base_of = decltype(is_base_of_test_func<Base>(declval<Derived*>()));
// with <experimental/type_traits>:
// template <typename Base, typename Derived>
// using pre_is_base_of2 = experimental::detected_or_t<true_type, pre_is_base_of, Base, Derived>;
template <typename Base, typename Derived, typename = void>
struct pre_is_base_of2 : public true_type { };
// note void_t is a C++17 feature
template <typename Base, typename Derived>
struct pre_is_base_of2<Base, Derived, void_t<pre_is_base_of<Base, Derived>>> :
public pre_is_base_of<Base, Derived> { };
}
template <typename Base, typename Derived>
struct is_base_of :
public conditional_t<
is_class<Base>::value && is_class<Derived>::value,
details::pre_is_base_of2<Base, Derived>,
false_type
> { };
/// is_abstract
template <typename _Tp>
struct is_abstract
: public integral_constant<bool, __is_abstract(_Tp)>
{
};
// In N3290 is_destructible does not say anything about function
// types and abstract types, see LWG 2049. This implementation
// describes function types as trivially nothrow destructible and
// abstract types as destructible, iff the explicit destructor
// call expression is wellformed.
struct __do_is_destructible_impl_1
{
template <typename _Up>
struct __w
{
_Up __u;
};
template <typename _Tp, typename = decltype(declval<__w<_Tp> &>().~__w<_Tp>())>
static true_type __test(int);
template <typename>
static false_type __test(...);
};
template <typename _Tp>
struct __is_destructible_impl_1
: public __do_is_destructible_impl_1
{
typedef decltype(__test<_Tp>(0)) type;
};
// Special implementation for abstract types
struct __do_is_destructible_impl_2
{
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_2
: public __do_is_destructible_impl_2
{
typedef decltype(__test<_Tp>(0)) type;
};
template <typename _Tp,
bool = __or_<is_void<_Tp>,
__is_array_unknown_bounds<_Tp>>::value,
bool = __or_<is_reference<_Tp>, is_function<_Tp>>::value>
struct __is_destructible_safe;
template <typename _Tp>
struct __is_destructible_safe<_Tp, false, false>
: public conditional<is_abstract<_Tp>::value,
__is_destructible_impl_2<_Tp>,
__is_destructible_impl_1<_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 integral_constant<bool, (__is_destructible_safe<_Tp>::value)>
{
};
/// is_default_constructible
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
{
};
// Implementation of is_constructible.
// 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.
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(...);
};
template <typename _Tp, typename _Arg>
struct __is_direct_constructible_impl
: public __do_is_direct_constructible_impl
{
typedef decltype(__test<_Tp, _Arg>(0)) type;
};
template <typename _Tp, typename _Arg>
struct __is_direct_constructible_new_safe
: public __and_<is_destructible<_Tp>,
__is_direct_constructible_impl<_Tp, _Arg>>::type
{
};
template <typename, typename>
struct is_same;
template< class T, class U >
inline constexpr bool is_same_v = is_same<T, U>::value;
template <typename, typename>
struct is_base_of;
template <typename>
struct remove_reference;
template <typename _From, typename _To, bool = is_reference<_From>::value>
struct __is_base_to_derived_ref;
template <typename _From, typename _To>
struct __is_base_to_derived_ref<_From, _To, true>
{
typedef typename remove_cv<typename remove_reference<_From>::type>::type __src_t;
typedef typename remove_cv<typename remove_reference<_To>::type>::type __dst_t;
typedef __and_<__not_<is_same<__src_t, __dst_t>>,
is_base_of<__src_t, __dst_t>>
type;
static constexpr bool value = type::value;
};
template <typename _From, typename _To>
struct __is_base_to_derived_ref<_From, _To, false>
: public false_type
{
};
template <typename _From, typename _To, bool = __and_<is_lvalue_reference<_From>, is_rvalue_reference<_To>>::value>
struct __is_lvalue_to_rvalue_ref;
template <typename _From, typename _To>
struct __is_lvalue_to_rvalue_ref<_From, _To, true>
{
typedef typename remove_cv<typename remove_reference<
_From>::type>::type __src_t;
typedef typename remove_cv<typename remove_reference<
_To>::type>::type __dst_t;
typedef __or_<is_same<__src_t, __dst_t>,
is_base_of<__dst_t, __src_t>>
type;
static constexpr bool value = type::value;
};
template <typename _From, typename _To>
struct __is_lvalue_to_rvalue_ref<_From, _To, false>
: public false_type
{
};
// Here we handle direct-initialization to a reference type as
// equivalent to a static_cast modulo overshooting conversions.
// These are restricted to the following conversions:
// a) A glvalue of a base class to a derived class reference
// b) An lvalue to an rvalue-reference of reference-compatible
// types
template <typename _Tp, typename _Arg>
struct __is_direct_constructible_ref_cast
: public __and_<__is_static_castable<_Arg, _Tp>,
__not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
__is_lvalue_to_rvalue_ref<_Arg, _Tp>>>>::type
{
};
template <typename _Tp, typename _Arg>
struct __is_direct_constructible_new
: public conditional<is_reference<_Tp>::value,
__is_direct_constructible_ref_cast<_Tp, _Arg>,
__is_direct_constructible_new_safe<_Tp, _Arg>>::type
{
};
template <typename _Tp, typename _Arg>
struct __is_direct_constructible
: public integral_constant<bool, (__is_direct_constructible_new<
_Tp, _Arg>::value)>
{
};
// Since default-construction and binary direct-initialization have
// been handled separately, the implementation of the remaining
// n-ary construction cases is rather straightforward.
struct __do_is_nary_constructible_impl
{
template <typename _Tp, typename... _Args, typename = decltype(_Tp(declval<_Args>()...))>
static true_type __test(int);
template <typename, typename...>
static false_type __test(...);
};
template <typename _Tp, typename... _Args>
struct __is_nary_constructible_impl
: public __do_is_nary_constructible_impl
{
typedef decltype(__test<_Tp, _Args...>(0)) type;
};
template <typename _Tp, typename... _Args>
struct __is_nary_constructible
: public __is_nary_constructible_impl<_Tp, _Args...>::type
{
static_assert(sizeof...(_Args) > 1,
"Only useful for > 1 arguments");
};
template <typename _Tp, typename... _Args>
struct __is_constructible_impl
: public __is_nary_constructible<_Tp, _Args...>
{
};
template <typename _Tp, typename _Arg>
struct __is_constructible_impl<_Tp, _Arg>
: public __is_direct_constructible<_Tp, _Arg>