1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/type_traits
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_TYPE_TRAITS
30 #define _GLIBCXX_TYPE_TRAITS 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
38 #include <bits/c++config.h>
40 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
41 # if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__)
44 typedef __UINT_LEAST16_TYPE__ uint_least16_t;
45 typedef __UINT_LEAST32_TYPE__ uint_least32_t;
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 * @defgroup metaprogramming Metaprogramming
60 * Template utilities for compile-time introspection and modification,
61 * including type classification traits, type property inspection traits
62 * and type transformation traits.
68 template<typename _Tp, _Tp __v>
69 struct integral_constant
71 static constexpr _Tp value = __v;
72 typedef _Tp value_type;
73 typedef integral_constant<_Tp, __v> type;
74 constexpr operator value_type() const { return value; }
75 #if __cplusplus > 201103L
76 constexpr value_type operator()() const { return value; }
80 template<typename _Tp, _Tp __v>
81 constexpr _Tp integral_constant<_Tp, __v>::value;
83 /// The type used as a compile-time boolean with true value.
84 typedef integral_constant<bool, true> true_type;
86 /// The type used as a compile-time boolean with false value.
87 typedef integral_constant<bool, false> false_type;
89 // Meta programming helper types.
91 template<bool, typename, typename>
102 template<typename _B1>
107 template<typename _B1, typename _B2>
108 struct __or_<_B1, _B2>
109 : public conditional<_B1::value, _B1, _B2>::type
112 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
113 struct __or_<_B1, _B2, _B3, _Bn...>
114 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
117 template<typename...>
125 template<typename _B1>
130 template<typename _B1, typename _B2>
131 struct __and_<_B1, _B2>
132 : public conditional<_B1::value, _B2, _B1>::type
135 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
136 struct __and_<_B1, _B2, _B3, _Bn...>
137 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
140 template<typename _Pp>
142 : public integral_constant<bool, !_Pp::value>
145 // For several sfinae-friendly trait implementations we transport both the
146 // result information (as the member type) and the failure information (no
147 // member type). This is very similar to std::enable_if, but we cannot use
148 // them, because we need to derive from them as an implementation detail.
150 template<typename _Tp>
151 struct __success_type
152 { typedef _Tp type; };
154 struct __failure_type
157 // Primary type categories.
163 struct __is_void_helper
164 : public false_type { };
167 struct __is_void_helper<void>
168 : public true_type { };
171 template<typename _Tp>
173 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
177 struct __is_integral_helper
178 : public false_type { };
181 struct __is_integral_helper<bool>
182 : public true_type { };
185 struct __is_integral_helper<char>
186 : public true_type { };
189 struct __is_integral_helper<signed char>
190 : public true_type { };
193 struct __is_integral_helper<unsigned char>
194 : public true_type { };
196 #ifdef _GLIBCXX_USE_WCHAR_T
198 struct __is_integral_helper<wchar_t>
199 : public true_type { };
203 struct __is_integral_helper<char16_t>
204 : public true_type { };
207 struct __is_integral_helper<char32_t>
208 : public true_type { };
211 struct __is_integral_helper<short>
212 : public true_type { };
215 struct __is_integral_helper<unsigned short>
216 : public true_type { };
219 struct __is_integral_helper<int>
220 : public true_type { };
223 struct __is_integral_helper<unsigned int>
224 : public true_type { };
227 struct __is_integral_helper<long>
228 : public true_type { };
231 struct __is_integral_helper<unsigned long>
232 : public true_type { };
235 struct __is_integral_helper<long long>
236 : public true_type { };
239 struct __is_integral_helper<unsigned long long>
240 : public true_type { };
242 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
244 struct __is_integral_helper<__int128>
245 : public true_type { };
248 struct __is_integral_helper<unsigned __int128>
249 : public true_type { };
253 template<typename _Tp>
255 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
259 struct __is_floating_point_helper
260 : public false_type { };
263 struct __is_floating_point_helper<float>
264 : public true_type { };
267 struct __is_floating_point_helper<double>
268 : public true_type { };
271 struct __is_floating_point_helper<long double>
272 : public true_type { };
274 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
276 struct __is_floating_point_helper<__float128>
277 : public true_type { };
280 /// is_floating_point
281 template<typename _Tp>
282 struct is_floating_point
283 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
289 : public false_type { };
291 template<typename _Tp, std::size_t _Size>
292 struct is_array<_Tp[_Size]>
293 : public true_type { };
295 template<typename _Tp>
296 struct is_array<_Tp[]>
297 : public true_type { };
300 struct __is_pointer_helper
301 : public false_type { };
303 template<typename _Tp>
304 struct __is_pointer_helper<_Tp*>
305 : public true_type { };
308 template<typename _Tp>
310 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
313 /// is_lvalue_reference
315 struct is_lvalue_reference
316 : public false_type { };
318 template<typename _Tp>
319 struct is_lvalue_reference<_Tp&>
320 : public true_type { };
322 /// is_rvalue_reference
324 struct is_rvalue_reference
325 : public false_type { };
327 template<typename _Tp>
328 struct is_rvalue_reference<_Tp&&>
329 : public true_type { };
335 struct __is_member_object_pointer_helper
336 : public false_type { };
338 template<typename _Tp, typename _Cp>
339 struct __is_member_object_pointer_helper<_Tp _Cp::*>
340 : public integral_constant<bool, !is_function<_Tp>::value> { };
342 /// is_member_object_pointer
343 template<typename _Tp>
344 struct is_member_object_pointer
345 : public __is_member_object_pointer_helper<
346 typename remove_cv<_Tp>::type>::type
350 struct __is_member_function_pointer_helper
351 : public false_type { };
353 template<typename _Tp, typename _Cp>
354 struct __is_member_function_pointer_helper<_Tp _Cp::*>
355 : public integral_constant<bool, is_function<_Tp>::value> { };
357 /// is_member_function_pointer
358 template<typename _Tp>
359 struct is_member_function_pointer
360 : public __is_member_function_pointer_helper<
361 typename remove_cv<_Tp>::type>::type
365 template<typename _Tp>
367 : public integral_constant<bool, __is_enum(_Tp)>
371 template<typename _Tp>
373 : public integral_constant<bool, __is_union(_Tp)>
377 template<typename _Tp>
379 : public integral_constant<bool, __is_class(_Tp)>
385 : public false_type { };
387 template<typename _Res, typename... _ArgTypes>
388 struct is_function<_Res(_ArgTypes...)>
389 : public true_type { };
391 template<typename _Res, typename... _ArgTypes>
392 struct is_function<_Res(_ArgTypes...) &>
393 : public true_type { };
395 template<typename _Res, typename... _ArgTypes>
396 struct is_function<_Res(_ArgTypes...) &&>
397 : public true_type { };
399 template<typename _Res, typename... _ArgTypes>
400 struct is_function<_Res(_ArgTypes......)>
401 : public true_type { };
403 template<typename _Res, typename... _ArgTypes>
404 struct is_function<_Res(_ArgTypes......) &>
405 : public true_type { };
407 template<typename _Res, typename... _ArgTypes>
408 struct is_function<_Res(_ArgTypes......) &&>
409 : public true_type { };
411 template<typename _Res, typename... _ArgTypes>
412 struct is_function<_Res(_ArgTypes...) const>
413 : public true_type { };
415 template<typename _Res, typename... _ArgTypes>
416 struct is_function<_Res(_ArgTypes...) const &>
417 : public true_type { };
419 template<typename _Res, typename... _ArgTypes>
420 struct is_function<_Res(_ArgTypes...) const &&>
421 : public true_type { };
423 template<typename _Res, typename... _ArgTypes>
424 struct is_function<_Res(_ArgTypes......) const>
425 : public true_type { };
427 template<typename _Res, typename... _ArgTypes>
428 struct is_function<_Res(_ArgTypes......) const &>
429 : public true_type { };
431 template<typename _Res, typename... _ArgTypes>
432 struct is_function<_Res(_ArgTypes......) const &&>
433 : public true_type { };
435 template<typename _Res, typename... _ArgTypes>
436 struct is_function<_Res(_ArgTypes...) volatile>
437 : public true_type { };
439 template<typename _Res, typename... _ArgTypes>
440 struct is_function<_Res(_ArgTypes...) volatile &>
441 : public true_type { };
443 template<typename _Res, typename... _ArgTypes>
444 struct is_function<_Res(_ArgTypes...) volatile &&>
445 : public true_type { };
447 template<typename _Res, typename... _ArgTypes>
448 struct is_function<_Res(_ArgTypes......) volatile>
449 : public true_type { };
451 template<typename _Res, typename... _ArgTypes>
452 struct is_function<_Res(_ArgTypes......) volatile &>
453 : public true_type { };
455 template<typename _Res, typename... _ArgTypes>
456 struct is_function<_Res(_ArgTypes......) volatile &&>
457 : public true_type { };
459 template<typename _Res, typename... _ArgTypes>
460 struct is_function<_Res(_ArgTypes...) const volatile>
461 : public true_type { };
463 template<typename _Res, typename... _ArgTypes>
464 struct is_function<_Res(_ArgTypes...) const volatile &>
465 : public true_type { };
467 template<typename _Res, typename... _ArgTypes>
468 struct is_function<_Res(_ArgTypes...) const volatile &&>
469 : public true_type { };
471 template<typename _Res, typename... _ArgTypes>
472 struct is_function<_Res(_ArgTypes......) const volatile>
473 : public true_type { };
475 template<typename _Res, typename... _ArgTypes>
476 struct is_function<_Res(_ArgTypes......) const volatile &>
477 : public true_type { };
479 template<typename _Res, typename... _ArgTypes>
480 struct is_function<_Res(_ArgTypes......) const volatile &&>
481 : public true_type { };
484 struct __is_null_pointer_helper
485 : public false_type { };
488 struct __is_null_pointer_helper<std::nullptr_t>
489 : public true_type { };
491 /// is_null_pointer (LWG 2247).
492 template<typename _Tp>
493 struct is_null_pointer
494 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
497 /// __is_nullptr_t (extension).
498 template<typename _Tp>
499 struct __is_nullptr_t
500 : public is_null_pointer<_Tp>
503 // Composite type categories.
506 template<typename _Tp>
508 : public __or_<is_lvalue_reference<_Tp>,
509 is_rvalue_reference<_Tp>>::type
513 template<typename _Tp>
515 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
519 template<typename _Tp>
520 struct is_fundamental
521 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
522 is_null_pointer<_Tp>>::type
526 template<typename _Tp>
528 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
533 struct is_member_pointer;
536 template<typename _Tp>
538 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
539 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
543 template<typename _Tp>
545 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
547 template<typename _Tp>
548 struct __is_member_pointer_helper
549 : public false_type { };
551 template<typename _Tp, typename _Cp>
552 struct __is_member_pointer_helper<_Tp _Cp::*>
553 : public true_type { };
555 /// is_member_pointer
556 template<typename _Tp>
557 struct is_member_pointer
558 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
561 // Utility to detect referenceable types ([defns.referenceable]).
563 template<typename _Tp>
564 struct __is_referenceable
565 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
568 template<typename _Res, typename... _Args>
569 struct __is_referenceable<_Res(_Args...)>
573 template<typename _Res, typename... _Args>
574 struct __is_referenceable<_Res(_Args......)>
583 : public false_type { };
585 template<typename _Tp>
586 struct is_const<_Tp const>
587 : public true_type { };
592 : public false_type { };
594 template<typename _Tp>
595 struct is_volatile<_Tp volatile>
596 : public true_type { };
599 template<typename _Tp>
601 : public integral_constant<bool, __is_trivial(_Tp)>
604 // is_trivially_copyable (still unimplemented)
606 /// is_standard_layout
607 template<typename _Tp>
608 struct is_standard_layout
609 : public integral_constant<bool, __is_standard_layout(_Tp)>
613 // Could use is_standard_layout && is_trivial instead of the builtin.
614 template<typename _Tp>
616 : public integral_constant<bool, __is_pod(_Tp)>
620 template<typename _Tp>
621 struct is_literal_type
622 : public integral_constant<bool, __is_literal_type(_Tp)>
626 template<typename _Tp>
628 : public integral_constant<bool, __is_empty(_Tp)>
632 template<typename _Tp>
633 struct is_polymorphic
634 : public integral_constant<bool, __is_polymorphic(_Tp)>
637 #if __cplusplus > 201103L
639 template<typename _Tp>
641 : public integral_constant<bool, __is_final(_Tp)>
646 template<typename _Tp>
648 : public integral_constant<bool, __is_abstract(_Tp)>
651 template<typename _Tp,
652 bool = is_arithmetic<_Tp>::value>
653 struct __is_signed_helper
654 : public false_type { };
656 template<typename _Tp>
657 struct __is_signed_helper<_Tp, true>
658 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
662 template<typename _Tp>
664 : public __is_signed_helper<_Tp>::type
668 template<typename _Tp>
670 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
674 // Destructible and constructible type properties.
677 struct add_rvalue_reference;
680 * @brief Utility to simplify expressions used in unevaluated operands
683 template<typename _Tp>
684 typename add_rvalue_reference<_Tp>::type declval() noexcept;
686 template<typename, unsigned = 0>
690 struct remove_all_extents;
692 template<typename _Tp>
693 struct __is_array_known_bounds
694 : public integral_constant<bool, (extent<_Tp>::value > 0)>
697 template<typename _Tp>
698 struct __is_array_unknown_bounds
699 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
702 // In N3290 is_destructible does not say anything about function
703 // types and abstract types, see LWG 2049. This implementation
704 // describes function types as non-destructible and all complete
705 // object types as destructible, iff the explicit destructor
706 // call expression is wellformed.
707 struct __do_is_destructible_impl
709 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
710 static true_type __test(int);
713 static false_type __test(...);
716 template<typename _Tp>
717 struct __is_destructible_impl
718 : public __do_is_destructible_impl
720 typedef decltype(__test<_Tp>(0)) type;
723 template<typename _Tp,
724 bool = __or_<is_void<_Tp>,
725 __is_array_unknown_bounds<_Tp>,
726 is_function<_Tp>>::value,
727 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
728 struct __is_destructible_safe;
730 template<typename _Tp>
731 struct __is_destructible_safe<_Tp, false, false>
732 : public __is_destructible_impl<typename
733 remove_all_extents<_Tp>::type>::type
736 template<typename _Tp>
737 struct __is_destructible_safe<_Tp, true, false>
738 : public false_type { };
740 template<typename _Tp>
741 struct __is_destructible_safe<_Tp, false, true>
742 : public true_type { };
745 template<typename _Tp>
746 struct is_destructible
747 : public __is_destructible_safe<_Tp>::type
750 // is_nothrow_destructible requires that is_destructible is
751 // satisfied as well. We realize that by mimicing the
752 // implementation of is_destructible but refer to noexcept(expr)
753 // instead of decltype(expr).
754 struct __do_is_nt_destructible_impl
756 template<typename _Tp>
757 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
761 static false_type __test(...);
764 template<typename _Tp>
765 struct __is_nt_destructible_impl
766 : public __do_is_nt_destructible_impl
768 typedef decltype(__test<_Tp>(0)) type;
771 template<typename _Tp,
772 bool = __or_<is_void<_Tp>,
773 __is_array_unknown_bounds<_Tp>,
774 is_function<_Tp>>::value,
775 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
776 struct __is_nt_destructible_safe;
778 template<typename _Tp>
779 struct __is_nt_destructible_safe<_Tp, false, false>
780 : public __is_nt_destructible_impl<typename
781 remove_all_extents<_Tp>::type>::type
784 template<typename _Tp>
785 struct __is_nt_destructible_safe<_Tp, true, false>
786 : public false_type { };
788 template<typename _Tp>
789 struct __is_nt_destructible_safe<_Tp, false, true>
790 : public true_type { };
792 /// is_nothrow_destructible
793 template<typename _Tp>
794 struct is_nothrow_destructible
795 : public __is_nt_destructible_safe<_Tp>::type
798 struct __do_is_default_constructible_impl
800 template<typename _Tp, typename = decltype(_Tp())>
801 static true_type __test(int);
804 static false_type __test(...);
807 template<typename _Tp>
808 struct __is_default_constructible_impl
809 : public __do_is_default_constructible_impl
811 typedef decltype(__test<_Tp>(0)) type;
814 template<typename _Tp>
815 struct __is_default_constructible_atom
816 : public __and_<__not_<is_void<_Tp>>,
817 __is_default_constructible_impl<_Tp>>::type
820 template<typename _Tp, bool = is_array<_Tp>::value>
821 struct __is_default_constructible_safe;
823 // The following technique is a workaround for a current core language
824 // restriction, which does not allow for array types to occur in
825 // functional casts of the form T(). Complete arrays can be default-
826 // constructed, if the element type is default-constructible, but
827 // arrays with unknown bounds are not.
828 template<typename _Tp>
829 struct __is_default_constructible_safe<_Tp, true>
830 : public __and_<__is_array_known_bounds<_Tp>,
831 __is_default_constructible_atom<typename
832 remove_all_extents<_Tp>::type>>::type
835 template<typename _Tp>
836 struct __is_default_constructible_safe<_Tp, false>
837 : public __is_default_constructible_atom<_Tp>::type
840 /// is_default_constructible
841 template<typename _Tp>
842 struct is_default_constructible
843 : public __is_default_constructible_safe<_Tp>::type
847 // Implementation of is_constructible.
849 // The hardest part of this trait is the binary direct-initialization
850 // case, because we hit into a functional cast of the form T(arg).
851 // This implementation uses different strategies depending on the
852 // target type to reduce the test overhead as much as possible:
854 // a) For a reference target type, we use a static_cast expression
855 // modulo its extra cases.
857 // b) For a non-reference target type we use a ::new expression.
858 struct __do_is_static_castable_impl
860 template<typename _From, typename _To, typename
861 = decltype(static_cast<_To>(declval<_From>()))>
862 static true_type __test(int);
864 template<typename, typename>
865 static false_type __test(...);
868 template<typename _From, typename _To>
869 struct __is_static_castable_impl
870 : public __do_is_static_castable_impl
872 typedef decltype(__test<_From, _To>(0)) type;
875 template<typename _From, typename _To>
876 struct __is_static_castable_safe
877 : public __is_static_castable_impl<_From, _To>::type
880 // __is_static_castable
881 template<typename _From, typename _To>
882 struct __is_static_castable
883 : public integral_constant<bool, (__is_static_castable_safe<
887 // Implementation for non-reference types. To meet the proper
888 // variable definition semantics, we also need to test for
889 // is_destructible in this case.
890 // This form should be simplified by a single expression:
891 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
892 struct __do_is_direct_constructible_impl
894 template<typename _Tp, typename _Arg, typename
895 = decltype(::new _Tp(declval<_Arg>()))>
896 static true_type __test(int);
898 template<typename, typename>
899 static false_type __test(...);
902 template<typename _Tp, typename _Arg>
903 struct __is_direct_constructible_impl
904 : public __do_is_direct_constructible_impl
906 typedef decltype(__test<_Tp, _Arg>(0)) type;
909 template<typename _Tp, typename _Arg>
910 struct __is_direct_constructible_new_safe
911 : public __and_<is_destructible<_Tp>,
912 __is_direct_constructible_impl<_Tp, _Arg>>::type
915 template<typename, typename>
918 template<typename, typename>
922 struct remove_reference;
924 template<typename _From, typename _To, bool
925 = __not_<__or_<is_void<_From>,
926 is_function<_From>>>::value>
927 struct __is_base_to_derived_ref;
929 // Detect whether we have a downcast situation during
930 // reference binding.
931 template<typename _From, typename _To>
932 struct __is_base_to_derived_ref<_From, _To, true>
934 typedef typename remove_cv<typename remove_reference<_From
935 >::type>::type __src_t;
936 typedef typename remove_cv<typename remove_reference<_To
937 >::type>::type __dst_t;
938 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
939 is_base_of<__src_t, __dst_t>> type;
940 static constexpr bool value = type::value;
943 template<typename _From, typename _To>
944 struct __is_base_to_derived_ref<_From, _To, false>
948 template<typename _From, typename _To, bool
949 = __and_<is_lvalue_reference<_From>,
950 is_rvalue_reference<_To>>::value>
951 struct __is_lvalue_to_rvalue_ref;
953 // Detect whether we have an lvalue of non-function type
954 // bound to a reference-compatible rvalue-reference.
955 template<typename _From, typename _To>
956 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
958 typedef typename remove_cv<typename remove_reference<
959 _From>::type>::type __src_t;
960 typedef typename remove_cv<typename remove_reference<
961 _To>::type>::type __dst_t;
962 typedef __and_<__not_<is_function<__src_t>>,
963 __or_<is_same<__src_t, __dst_t>,
964 is_base_of<__dst_t, __src_t>>> type;
965 static constexpr bool value = type::value;
968 template<typename _From, typename _To>
969 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
973 // Here we handle direct-initialization to a reference type as
974 // equivalent to a static_cast modulo overshooting conversions.
975 // These are restricted to the following conversions:
976 // a) A base class value to a derived class reference
977 // b) An lvalue to an rvalue-reference of reference-compatible
978 // types that are not functions
979 template<typename _Tp, typename _Arg>
980 struct __is_direct_constructible_ref_cast
981 : public __and_<__is_static_castable<_Arg, _Tp>,
982 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
983 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
987 template<typename _Tp, typename _Arg>
988 struct __is_direct_constructible_new
989 : public conditional<is_reference<_Tp>::value,
990 __is_direct_constructible_ref_cast<_Tp, _Arg>,
991 __is_direct_constructible_new_safe<_Tp, _Arg>
995 template<typename _Tp, typename _Arg>
996 struct __is_direct_constructible
997 : public __is_direct_constructible_new<_Tp, _Arg>::type
1000 // Since default-construction and binary direct-initialization have
1001 // been handled separately, the implementation of the remaining
1002 // n-ary construction cases is rather straightforward. We can use
1003 // here a functional cast, because array types are excluded anyway
1004 // and this form is never interpreted as a C cast.
1005 struct __do_is_nary_constructible_impl
1007 template<typename _Tp, typename... _Args, typename
1008 = decltype(_Tp(declval<_Args>()...))>
1009 static true_type __test(int);
1011 template<typename, typename...>
1012 static false_type __test(...);
1015 template<typename _Tp, typename... _Args>
1016 struct __is_nary_constructible_impl
1017 : public __do_is_nary_constructible_impl
1019 typedef decltype(__test<_Tp, _Args...>(0)) type;
1022 template<typename _Tp, typename... _Args>
1023 struct __is_nary_constructible
1024 : public __is_nary_constructible_impl<_Tp, _Args...>::type
1026 static_assert(sizeof...(_Args) > 1,
1027 "Only useful for > 1 arguments");
1030 template<typename _Tp, typename... _Args>
1031 struct __is_constructible_impl
1032 : public __is_nary_constructible<_Tp, _Args...>
1035 template<typename _Tp, typename _Arg>
1036 struct __is_constructible_impl<_Tp, _Arg>
1037 : public __is_direct_constructible<_Tp, _Arg>
1040 template<typename _Tp>
1041 struct __is_constructible_impl<_Tp>
1042 : public is_default_constructible<_Tp>
1045 /// is_constructible
1046 template<typename _Tp, typename... _Args>
1047 struct is_constructible
1048 : public __is_constructible_impl<_Tp, _Args...>::type
1051 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1052 struct __is_copy_constructible_impl;
1054 template<typename _Tp>
1055 struct __is_copy_constructible_impl<_Tp, false>
1056 : public false_type { };
1058 template<typename _Tp>
1059 struct __is_copy_constructible_impl<_Tp, true>
1060 : public is_constructible<_Tp, const _Tp&>
1063 /// is_copy_constructible
1064 template<typename _Tp>
1065 struct is_copy_constructible
1066 : public __is_copy_constructible_impl<_Tp>
1069 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1070 struct __is_move_constructible_impl;
1072 template<typename _Tp>
1073 struct __is_move_constructible_impl<_Tp, false>
1074 : public false_type { };
1076 template<typename _Tp>
1077 struct __is_move_constructible_impl<_Tp, true>
1078 : public is_constructible<_Tp, _Tp&&>
1081 /// is_move_constructible
1082 template<typename _Tp>
1083 struct is_move_constructible
1084 : public __is_move_constructible_impl<_Tp>
1087 template<typename _Tp>
1088 struct __is_nt_default_constructible_atom
1089 : public integral_constant<bool, noexcept(_Tp())>
1092 template<typename _Tp, bool = is_array<_Tp>::value>
1093 struct __is_nt_default_constructible_impl;
1095 template<typename _Tp>
1096 struct __is_nt_default_constructible_impl<_Tp, true>
1097 : public __and_<__is_array_known_bounds<_Tp>,
1098 __is_nt_default_constructible_atom<typename
1099 remove_all_extents<_Tp>::type>>::type
1102 template<typename _Tp>
1103 struct __is_nt_default_constructible_impl<_Tp, false>
1104 : public __is_nt_default_constructible_atom<_Tp>
1107 /// is_nothrow_default_constructible
1108 template<typename _Tp>
1109 struct is_nothrow_default_constructible
1110 : public __and_<is_default_constructible<_Tp>,
1111 __is_nt_default_constructible_impl<_Tp>>::type
1114 template<typename _Tp, typename... _Args>
1115 struct __is_nt_constructible_impl
1116 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1119 template<typename _Tp, typename _Arg>
1120 struct __is_nt_constructible_impl<_Tp, _Arg>
1121 : public integral_constant<bool,
1122 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1125 template<typename _Tp>
1126 struct __is_nt_constructible_impl<_Tp>
1127 : public is_nothrow_default_constructible<_Tp>
1130 /// is_nothrow_constructible
1131 template<typename _Tp, typename... _Args>
1132 struct is_nothrow_constructible
1133 : public __and_<is_constructible<_Tp, _Args...>,
1134 __is_nt_constructible_impl<_Tp, _Args...>>::type
1137 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1138 struct __is_nothrow_copy_constructible_impl;
1140 template<typename _Tp>
1141 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1142 : public false_type { };
1144 template<typename _Tp>
1145 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1146 : public is_nothrow_constructible<_Tp, const _Tp&>
1149 /// is_nothrow_copy_constructible
1150 template<typename _Tp>
1151 struct is_nothrow_copy_constructible
1152 : public __is_nothrow_copy_constructible_impl<_Tp>
1155 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1156 struct __is_nothrow_move_constructible_impl;
1158 template<typename _Tp>
1159 struct __is_nothrow_move_constructible_impl<_Tp, false>
1160 : public false_type { };
1162 template<typename _Tp>
1163 struct __is_nothrow_move_constructible_impl<_Tp, true>
1164 : public is_nothrow_constructible<_Tp, _Tp&&>
1167 /// is_nothrow_move_constructible
1168 template<typename _Tp>
1169 struct is_nothrow_move_constructible
1170 : public __is_nothrow_move_constructible_impl<_Tp>
1173 template<typename _Tp, typename _Up>
1174 class __is_assignable_helper
1176 template<typename _Tp1, typename _Up1,
1177 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1181 template<typename, typename>
1186 typedef decltype(__test<_Tp, _Up>(0)) type;
1190 template<typename _Tp, typename _Up>
1191 struct is_assignable
1192 : public __is_assignable_helper<_Tp, _Up>::type
1195 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1196 struct __is_copy_assignable_impl;
1198 template<typename _Tp>
1199 struct __is_copy_assignable_impl<_Tp, false>
1200 : public false_type { };
1202 template<typename _Tp>
1203 struct __is_copy_assignable_impl<_Tp, true>
1204 : public is_assignable<_Tp&, const _Tp&>
1207 /// is_copy_assignable
1208 template<typename _Tp>
1209 struct is_copy_assignable
1210 : public __is_copy_assignable_impl<_Tp>
1213 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1214 struct __is_move_assignable_impl;
1216 template<typename _Tp>
1217 struct __is_move_assignable_impl<_Tp, false>
1218 : public false_type { };
1220 template<typename _Tp>
1221 struct __is_move_assignable_impl<_Tp, true>
1222 : public is_assignable<_Tp&, _Tp&&>
1225 /// is_move_assignable
1226 template<typename _Tp>
1227 struct is_move_assignable
1228 : public __is_move_assignable_impl<_Tp>
1231 template<typename _Tp, typename _Up>
1232 struct __is_nt_assignable_impl
1233 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1236 /// is_nothrow_assignable
1237 template<typename _Tp, typename _Up>
1238 struct is_nothrow_assignable
1239 : public __and_<is_assignable<_Tp, _Up>,
1240 __is_nt_assignable_impl<_Tp, _Up>>::type
1243 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1244 struct __is_nt_copy_assignable_impl;
1246 template<typename _Tp>
1247 struct __is_nt_copy_assignable_impl<_Tp, false>
1248 : public false_type { };
1250 template<typename _Tp>
1251 struct __is_nt_copy_assignable_impl<_Tp, true>
1252 : public is_nothrow_assignable<_Tp&, const _Tp&>
1255 /// is_nothrow_copy_assignable
1256 template<typename _Tp>
1257 struct is_nothrow_copy_assignable
1258 : public __is_nt_copy_assignable_impl<_Tp>
1261 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1262 struct __is_nt_move_assignable_impl;
1264 template<typename _Tp>
1265 struct __is_nt_move_assignable_impl<_Tp, false>
1266 : public false_type { };
1268 template<typename _Tp>
1269 struct __is_nt_move_assignable_impl<_Tp, true>
1270 : public is_nothrow_assignable<_Tp&, _Tp&&>
1273 /// is_nothrow_move_assignable
1274 template<typename _Tp>
1275 struct is_nothrow_move_assignable
1276 : public __is_nt_move_assignable_impl<_Tp>
1279 /// is_trivially_constructible (still unimplemented)
1281 /// is_trivially_default_constructible (still unimplemented)
1283 /// is_trivially_copy_constructible (still unimplemented)
1285 /// is_trivially_move_constructible (still unimplemented)
1287 /// is_trivially_assignable (still unimplemented)
1289 /// is_trivially_copy_assignable (still unimplemented)
1291 /// is_trivially_move_assignable (still unimplemented)
1293 /// is_trivially_destructible
1294 template<typename _Tp>
1295 struct is_trivially_destructible
1296 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1297 __has_trivial_destructor(_Tp)>>::type
1300 /// has_trivial_default_constructor (temporary legacy)
1301 template<typename _Tp>
1302 struct has_trivial_default_constructor
1303 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1306 /// has_trivial_copy_constructor (temporary legacy)
1307 template<typename _Tp>
1308 struct has_trivial_copy_constructor
1309 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1312 /// has_trivial_copy_assign (temporary legacy)
1313 template<typename _Tp>
1314 struct has_trivial_copy_assign
1315 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1318 /// has_virtual_destructor
1319 template<typename _Tp>
1320 struct has_virtual_destructor
1321 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1325 // type property queries.
1328 template<typename _Tp>
1330 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1335 : public integral_constant<std::size_t, 0> { };
1337 template<typename _Tp, std::size_t _Size>
1338 struct rank<_Tp[_Size]>
1339 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1341 template<typename _Tp>
1343 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1346 template<typename, unsigned _Uint>
1348 : public integral_constant<std::size_t, 0> { };
1350 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1351 struct extent<_Tp[_Size], _Uint>
1352 : public integral_constant<std::size_t,
1353 _Uint == 0 ? _Size : extent<_Tp,
1357 template<typename _Tp, unsigned _Uint>
1358 struct extent<_Tp[], _Uint>
1359 : public integral_constant<std::size_t,
1360 _Uint == 0 ? 0 : extent<_Tp,
1368 template<typename, typename>
1370 : public false_type { };
1372 template<typename _Tp>
1373 struct is_same<_Tp, _Tp>
1374 : public true_type { };
1377 template<typename _Base, typename _Derived>
1379 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1382 template<typename _From, typename _To,
1383 bool = __or_<is_void<_From>, is_function<_To>,
1384 is_array<_To>>::value>
1385 struct __is_convertible_helper
1386 { typedef typename is_void<_To>::type type; };
1388 template<typename _From, typename _To>
1389 class __is_convertible_helper<_From, _To, false>
1391 template<typename _To1>
1392 static void __test_aux(_To1);
1394 template<typename _From1, typename _To1,
1395 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1399 template<typename, typename>
1404 typedef decltype(__test<_From, _To>(0)) type;
1409 template<typename _From, typename _To>
1410 struct is_convertible
1411 : public __is_convertible_helper<_From, _To>::type
1415 // Const-volatile modifications.
1418 template<typename _Tp>
1420 { typedef _Tp type; };
1422 template<typename _Tp>
1423 struct remove_const<_Tp const>
1424 { typedef _Tp type; };
1427 template<typename _Tp>
1428 struct remove_volatile
1429 { typedef _Tp type; };
1431 template<typename _Tp>
1432 struct remove_volatile<_Tp volatile>
1433 { typedef _Tp type; };
1436 template<typename _Tp>
1440 remove_const<typename remove_volatile<_Tp>::type>::type type;
1444 template<typename _Tp>
1446 { typedef _Tp const type; };
1449 template<typename _Tp>
1451 { typedef _Tp volatile type; };
1454 template<typename _Tp>
1458 add_const<typename add_volatile<_Tp>::type>::type type;
1461 #if __cplusplus > 201103L
1462 /// Alias template for remove_const
1463 template<typename _Tp>
1464 using remove_const_t = typename remove_const<_Tp>::type;
1466 /// Alias template for remove_volatile
1467 template<typename _Tp>
1468 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1470 /// Alias template for remove_cv
1471 template<typename _Tp>
1472 using remove_cv_t = typename remove_cv<_Tp>::type;
1474 /// Alias template for add_const
1475 template<typename _Tp>
1476 using add_const_t = typename add_const<_Tp>::type;
1478 /// Alias template for add_volatile
1479 template<typename _Tp>
1480 using add_volatile_t = typename add_volatile<_Tp>::type;
1482 /// Alias template for add_cv
1483 template<typename _Tp>
1484 using add_cv_t = typename add_cv<_Tp>::type;
1487 // Reference transformations.
1489 /// remove_reference
1490 template<typename _Tp>
1491 struct remove_reference
1492 { typedef _Tp type; };
1494 template<typename _Tp>
1495 struct remove_reference<_Tp&>
1496 { typedef _Tp type; };
1498 template<typename _Tp>
1499 struct remove_reference<_Tp&&>
1500 { typedef _Tp type; };
1502 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1503 struct __add_lvalue_reference_helper
1504 { typedef _Tp type; };
1506 template<typename _Tp>
1507 struct __add_lvalue_reference_helper<_Tp, true>
1508 { typedef _Tp& type; };
1510 /// add_lvalue_reference
1511 template<typename _Tp>
1512 struct add_lvalue_reference
1513 : public __add_lvalue_reference_helper<_Tp>
1516 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1517 struct __add_rvalue_reference_helper
1518 { typedef _Tp type; };
1520 template<typename _Tp>
1521 struct __add_rvalue_reference_helper<_Tp, true>
1522 { typedef _Tp&& type; };
1524 /// add_rvalue_reference
1525 template<typename _Tp>
1526 struct add_rvalue_reference
1527 : public __add_rvalue_reference_helper<_Tp>
1530 #if __cplusplus > 201103L
1531 /// Alias template for remove_reference
1532 template<typename _Tp>
1533 using remove_reference_t = typename remove_reference<_Tp>::type;
1535 /// Alias template for add_lvalue_reference
1536 template<typename _Tp>
1537 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1539 /// Alias template for add_rvalue_reference
1540 template<typename _Tp>
1541 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1544 // Sign modifications.
1546 // Utility for constructing identically cv-qualified types.
1547 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1548 struct __cv_selector;
1550 template<typename _Unqualified>
1551 struct __cv_selector<_Unqualified, false, false>
1552 { typedef _Unqualified __type; };
1554 template<typename _Unqualified>
1555 struct __cv_selector<_Unqualified, false, true>
1556 { typedef volatile _Unqualified __type; };
1558 template<typename _Unqualified>
1559 struct __cv_selector<_Unqualified, true, false>
1560 { typedef const _Unqualified __type; };
1562 template<typename _Unqualified>
1563 struct __cv_selector<_Unqualified, true, true>
1564 { typedef const volatile _Unqualified __type; };
1566 template<typename _Qualified, typename _Unqualified,
1567 bool _IsConst = is_const<_Qualified>::value,
1568 bool _IsVol = is_volatile<_Qualified>::value>
1569 class __match_cv_qualifiers
1571 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1574 typedef typename __match::__type __type;
1577 // Utility for finding the unsigned versions of signed integral types.
1578 template<typename _Tp>
1579 struct __make_unsigned
1580 { typedef _Tp __type; };
1583 struct __make_unsigned<char>
1584 { typedef unsigned char __type; };
1587 struct __make_unsigned<signed char>
1588 { typedef unsigned char __type; };
1591 struct __make_unsigned<short>
1592 { typedef unsigned short __type; };
1595 struct __make_unsigned<int>
1596 { typedef unsigned int __type; };
1599 struct __make_unsigned<long>
1600 { typedef unsigned long __type; };
1603 struct __make_unsigned<long long>
1604 { typedef unsigned long long __type; };
1606 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1608 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1612 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1614 struct __make_unsigned<__int128>
1615 { typedef unsigned __int128 __type; };
1618 // Select between integral and enum: not possible to be both.
1619 template<typename _Tp,
1620 bool _IsInt = is_integral<_Tp>::value,
1621 bool _IsEnum = is_enum<_Tp>::value>
1622 class __make_unsigned_selector;
1624 template<typename _Tp>
1625 class __make_unsigned_selector<_Tp, true, false>
1627 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1628 typedef typename __unsignedt::__type __unsigned_type;
1629 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1632 typedef typename __cv_unsigned::__type __type;
1635 template<typename _Tp>
1636 class __make_unsigned_selector<_Tp, false, true>
1638 // With -fshort-enums, an enum may be as small as a char.
1639 typedef unsigned char __smallest;
1640 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1641 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1642 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1643 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1644 typedef typename __cond2::type __cond2_type;
1645 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1646 typedef typename __cond1::type __cond1_type;
1649 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1652 // Given an integral/enum type, return the corresponding unsigned
1654 // Primary template.
1656 template<typename _Tp>
1657 struct make_unsigned
1658 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1660 // Integral, but don't define.
1662 struct make_unsigned<bool>;
1665 // Utility for finding the signed versions of unsigned integral types.
1666 template<typename _Tp>
1667 struct __make_signed
1668 { typedef _Tp __type; };
1671 struct __make_signed<char>
1672 { typedef signed char __type; };
1675 struct __make_signed<unsigned char>
1676 { typedef signed char __type; };
1679 struct __make_signed<unsigned short>
1680 { typedef signed short __type; };
1683 struct __make_signed<unsigned int>
1684 { typedef signed int __type; };
1687 struct __make_signed<unsigned long>
1688 { typedef signed long __type; };
1691 struct __make_signed<unsigned long long>
1692 { typedef signed long long __type; };
1694 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1696 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1700 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1702 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1705 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1709 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1711 struct __make_signed<unsigned __int128>
1712 { typedef __int128 __type; };
1715 // Select between integral and enum: not possible to be both.
1716 template<typename _Tp,
1717 bool _IsInt = is_integral<_Tp>::value,
1718 bool _IsEnum = is_enum<_Tp>::value>
1719 class __make_signed_selector;
1721 template<typename _Tp>
1722 class __make_signed_selector<_Tp, true, false>
1724 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1725 typedef typename __signedt::__type __signed_type;
1726 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1729 typedef typename __cv_signed::__type __type;
1732 template<typename _Tp>
1733 class __make_signed_selector<_Tp, false, true>
1735 // With -fshort-enums, an enum may be as small as a char.
1736 typedef signed char __smallest;
1737 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1738 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1739 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1740 typedef conditional<__b2, signed int, signed long> __cond2;
1741 typedef typename __cond2::type __cond2_type;
1742 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1743 typedef typename __cond1::type __cond1_type;
1746 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1749 // Given an integral/enum type, return the corresponding signed
1751 // Primary template.
1753 template<typename _Tp>
1755 { typedef typename __make_signed_selector<_Tp>::__type type; };
1757 // Integral, but don't define.
1759 struct make_signed<bool>;
1761 #if __cplusplus > 201103L
1762 /// Alias template for make_signed
1763 template<typename _Tp>
1764 using make_signed_t = typename make_signed<_Tp>::type;
1766 /// Alias template for make_unsigned
1767 template<typename _Tp>
1768 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1771 // Array modifications.
1774 template<typename _Tp>
1775 struct remove_extent
1776 { typedef _Tp type; };
1778 template<typename _Tp, std::size_t _Size>
1779 struct remove_extent<_Tp[_Size]>
1780 { typedef _Tp type; };
1782 template<typename _Tp>
1783 struct remove_extent<_Tp[]>
1784 { typedef _Tp type; };
1786 /// remove_all_extents
1787 template<typename _Tp>
1788 struct remove_all_extents
1789 { typedef _Tp type; };
1791 template<typename _Tp, std::size_t _Size>
1792 struct remove_all_extents<_Tp[_Size]>
1793 { typedef typename remove_all_extents<_Tp>::type type; };
1795 template<typename _Tp>
1796 struct remove_all_extents<_Tp[]>
1797 { typedef typename remove_all_extents<_Tp>::type type; };
1799 #if __cplusplus > 201103L
1800 /// Alias template for remove_extent
1801 template<typename _Tp>
1802 using remove_extent_t = typename remove_extent<_Tp>::type;
1804 /// Alias template for remove_all_extents
1805 template<typename _Tp>
1806 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1809 // Pointer modifications.
1811 template<typename _Tp, typename>
1812 struct __remove_pointer_helper
1813 { typedef _Tp type; };
1815 template<typename _Tp, typename _Up>
1816 struct __remove_pointer_helper<_Tp, _Up*>
1817 { typedef _Up type; };
1820 template<typename _Tp>
1821 struct remove_pointer
1822 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1826 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1827 is_void<_Tp>>::value>
1828 struct __add_pointer_helper
1829 { typedef _Tp type; };
1831 template<typename _Tp>
1832 struct __add_pointer_helper<_Tp, true>
1833 { typedef typename remove_reference<_Tp>::type* type; };
1835 template<typename _Tp>
1837 : public __add_pointer_helper<_Tp>
1840 #if __cplusplus > 201103L
1841 /// Alias template for remove_pointer
1842 template<typename _Tp>
1843 using remove_pointer_t = typename remove_pointer<_Tp>::type;
1845 /// Alias template for add_pointer
1846 template<typename _Tp>
1847 using add_pointer_t = typename add_pointer<_Tp>::type;
1850 template<std::size_t _Len>
1851 struct __aligned_storage_msa
1855 unsigned char __data[_Len];
1856 struct __attribute__((__aligned__)) { } __align;
1861 * @brief Alignment type.
1863 * The value of _Align is a default-alignment which shall be the
1864 * most stringent alignment requirement for any C++ object type
1865 * whose size is no greater than _Len (3.9). The member typedef
1866 * type shall be a POD type suitable for use as uninitialized
1867 * storage for any object whose size is at most _Len and whose
1868 * alignment is a divisor of _Align.
1870 template<std::size_t _Len, std::size_t _Align =
1871 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1872 struct aligned_storage
1876 unsigned char __data[_Len];
1877 struct __attribute__((__aligned__((_Align)))) { } __align;
1882 // Decay trait for arrays and functions, used for perfect forwarding
1883 // in make_pair, make_tuple, etc.
1884 template<typename _Up,
1885 bool _IsArray = is_array<_Up>::value,
1886 bool _IsFunction = is_function<_Up>::value>
1887 struct __decay_selector;
1890 template<typename _Up>
1891 struct __decay_selector<_Up, false, false>
1892 { typedef typename remove_cv<_Up>::type __type; };
1894 template<typename _Up>
1895 struct __decay_selector<_Up, true, false>
1896 { typedef typename remove_extent<_Up>::type* __type; };
1898 template<typename _Up>
1899 struct __decay_selector<_Up, false, true>
1900 { typedef typename add_pointer<_Up>::type __type; };
1903 template<typename _Tp>
1906 typedef typename remove_reference<_Tp>::type __remove_type;
1909 typedef typename __decay_selector<__remove_type>::__type type;
1912 template<typename _Tp>
1913 class reference_wrapper;
1915 // Helper which adds a reference to a type when given a reference_wrapper
1916 template<typename _Tp>
1917 struct __strip_reference_wrapper
1922 template<typename _Tp>
1923 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1925 typedef _Tp& __type;
1928 template<typename _Tp>
1929 struct __decay_and_strip
1931 typedef typename __strip_reference_wrapper<
1932 typename decay<_Tp>::type>::__type __type;
1936 // Primary template.
1937 /// Define a member typedef @c type only if a boolean constant is true.
1938 template<bool, typename _Tp = void>
1942 // Partial specialization for true.
1943 template<typename _Tp>
1944 struct enable_if<true, _Tp>
1945 { typedef _Tp type; };
1947 template<typename... _Cond>
1948 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
1950 // Primary template.
1951 /// Define a member typedef @c type to one of two argument types.
1952 template<bool _Cond, typename _Iftrue, typename _Iffalse>
1954 { typedef _Iftrue type; };
1956 // Partial specialization for false.
1957 template<typename _Iftrue, typename _Iffalse>
1958 struct conditional<false, _Iftrue, _Iffalse>
1959 { typedef _Iffalse type; };
1962 template<typename... _Tp>
1965 // Sfinae-friendly common_type implementation:
1967 struct __do_common_type_impl
1969 template<typename _Tp, typename _Up>
1970 static __success_type<typename decay<decltype
1971 (true ? std::declval<_Tp>()
1972 : std::declval<_Up>())>::type> _S_test(int);
1974 template<typename, typename>
1975 static __failure_type _S_test(...);
1978 template<typename _Tp, typename _Up>
1979 struct __common_type_impl
1980 : private __do_common_type_impl
1982 typedef decltype(_S_test<_Tp, _Up>(0)) type;
1985 struct __do_member_type_wrapper
1987 template<typename _Tp>
1988 static __success_type<typename _Tp::type> _S_test(int);
1991 static __failure_type _S_test(...);
1994 template<typename _Tp>
1995 struct __member_type_wrapper
1996 : private __do_member_type_wrapper
1998 typedef decltype(_S_test<_Tp>(0)) type;
2001 template<typename _CTp, typename... _Args>
2002 struct __expanded_common_type_wrapper
2004 typedef common_type<typename _CTp::type, _Args...> type;
2007 template<typename... _Args>
2008 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2009 { typedef __failure_type type; };
2011 template<typename _Tp>
2012 struct common_type<_Tp>
2013 { typedef typename decay<_Tp>::type type; };
2015 template<typename _Tp, typename _Up>
2016 struct common_type<_Tp, _Up>
2017 : public __common_type_impl<_Tp, _Up>::type
2020 template<typename _Tp, typename _Up, typename... _Vp>
2021 struct common_type<_Tp, _Up, _Vp...>
2022 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2023 common_type<_Tp, _Up>>::type, _Vp...>::type
2026 /// The underlying type of an enum.
2027 template<typename _Tp>
2028 struct underlying_type
2030 typedef __underlying_type(_Tp) type;
2033 template<typename _Tp>
2034 struct __declval_protector
2036 static const bool __stop = false;
2037 static typename add_rvalue_reference<_Tp>::type __delegate();
2040 template<typename _Tp>
2041 inline typename add_rvalue_reference<_Tp>::type
2044 static_assert(__declval_protector<_Tp>::__stop,
2045 "declval() must not be used!");
2046 return __declval_protector<_Tp>::__delegate();
2050 template<typename _Signature>
2053 // Sfinae-friendly result_of implementation:
2055 // [func.require] paragraph 1 bullet 1:
2056 struct __result_of_memfun_ref_impl
2058 template<typename _Fp, typename _Tp1, typename... _Args>
2059 static __success_type<decltype(
2060 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2063 template<typename...>
2064 static __failure_type _S_test(...);
2067 template<typename _MemPtr, typename _Arg, typename... _Args>
2068 struct __result_of_memfun_ref
2069 : private __result_of_memfun_ref_impl
2071 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2074 // [func.require] paragraph 1 bullet 2:
2075 struct __result_of_memfun_deref_impl
2077 template<typename _Fp, typename _Tp1, typename... _Args>
2078 static __success_type<decltype(
2079 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2082 template<typename...>
2083 static __failure_type _S_test(...);
2086 template<typename _MemPtr, typename _Arg, typename... _Args>
2087 struct __result_of_memfun_deref
2088 : private __result_of_memfun_deref_impl
2090 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2093 // [func.require] paragraph 1 bullet 3:
2094 struct __result_of_memobj_ref_impl
2096 template<typename _Fp, typename _Tp1>
2097 static __success_type<decltype(
2098 std::declval<_Tp1>().*std::declval<_Fp>()
2101 template<typename, typename>
2102 static __failure_type _S_test(...);
2105 template<typename _MemPtr, typename _Arg>
2106 struct __result_of_memobj_ref
2107 : private __result_of_memobj_ref_impl
2109 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2112 // [func.require] paragraph 1 bullet 4:
2113 struct __result_of_memobj_deref_impl
2115 template<typename _Fp, typename _Tp1>
2116 static __success_type<decltype(
2117 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2120 template<typename, typename>
2121 static __failure_type _S_test(...);
2124 template<typename _MemPtr, typename _Arg>
2125 struct __result_of_memobj_deref
2126 : private __result_of_memobj_deref_impl
2128 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2131 template<typename _MemPtr, typename _Arg>
2132 struct __result_of_memobj;
2134 template<typename _Res, typename _Class, typename _Arg>
2135 struct __result_of_memobj<_Res _Class::*, _Arg>
2137 typedef typename remove_cv<typename remove_reference<
2138 _Arg>::type>::type _Argval;
2139 typedef _Res _Class::* _MemPtr;
2140 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2141 is_base_of<_Class, _Argval>>::value,
2142 __result_of_memobj_ref<_MemPtr, _Arg>,
2143 __result_of_memobj_deref<_MemPtr, _Arg>
2147 template<typename _MemPtr, typename _Arg, typename... _Args>
2148 struct __result_of_memfun;
2150 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2151 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2153 typedef typename remove_cv<typename remove_reference<
2154 _Arg>::type>::type _Argval;
2155 typedef _Res _Class::* _MemPtr;
2156 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2157 is_base_of<_Class, _Argval>>::value,
2158 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2159 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2163 template<bool, bool, typename _Functor, typename... _ArgTypes>
2164 struct __result_of_impl
2166 typedef __failure_type type;
2169 template<typename _MemPtr, typename _Arg>
2170 struct __result_of_impl<true, false, _MemPtr, _Arg>
2171 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2174 template<typename _MemPtr, typename _Arg, typename... _Args>
2175 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2176 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2179 // [func.require] paragraph 1 bullet 5:
2180 struct __result_of_other_impl
2182 template<typename _Fn, typename... _Args>
2183 static __success_type<decltype(
2184 std::declval<_Fn>()(std::declval<_Args>()...)
2187 template<typename...>
2188 static __failure_type _S_test(...);
2191 template<typename _Functor, typename... _ArgTypes>
2192 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2193 : private __result_of_other_impl
2195 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2198 template<typename _Functor, typename... _ArgTypes>
2199 struct result_of<_Functor(_ArgTypes...)>
2200 : public __result_of_impl<
2201 is_member_object_pointer<
2202 typename remove_reference<_Functor>::type
2204 is_member_function_pointer<
2205 typename remove_reference<_Functor>::type
2207 _Functor, _ArgTypes...
2211 #if __cplusplus > 201103L
2212 /// Alias template for aligned_storage
2213 template<size_t _Len, size_t _Align =
2214 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2215 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2217 /// Alias template for decay
2218 template<typename _Tp>
2219 using decay_t = typename decay<_Tp>::type;
2221 /// Alias template for enable_if
2222 template<bool _Cond, typename _Tp = void>
2223 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2225 /// Alias template for conditional
2226 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2227 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2229 /// Alias template for common_type
2230 template<typename... _Tp>
2231 using common_type_t = typename common_type<_Tp...>::type;
2233 /// Alias template for underlying_type
2234 template<typename _Tp>
2235 using underlying_type_t = typename underlying_type<_Tp>::type;
2237 /// Alias template for result_of
2238 template<typename _Tp>
2239 using result_of_t = typename result_of<_Tp>::type;
2242 /// @} group metaprogramming
2245 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2246 * member type _NTYPE.
2248 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2249 template<typename _Tp> \
2250 class __has_##_NTYPE##_helper \
2252 template<typename _Up> \
2256 template<typename _Up> \
2257 static true_type __test(_Wrap_type<typename _Up::_NTYPE>*); \
2259 template<typename _Up> \
2260 static false_type __test(...); \
2263 typedef decltype(__test<_Tp>(0)) type; \
2266 template<typename _Tp> \
2267 struct __has_##_NTYPE \
2268 : public __has_##_NTYPE##_helper \
2269 <typename remove_cv<_Tp>::type>::type \
2272 _GLIBCXX_END_NAMESPACE_VERSION
2277 #endif // _GLIBCXX_TYPE_TRAITS