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)>
638 template<typename _Tp>
640 : public integral_constant<bool, __is_abstract(_Tp)>
643 template<typename _Tp,
644 bool = is_arithmetic<_Tp>::value>
645 struct __is_signed_helper
646 : public false_type { };
648 template<typename _Tp>
649 struct __is_signed_helper<_Tp, true>
650 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
654 template<typename _Tp>
656 : public __is_signed_helper<_Tp>::type
660 template<typename _Tp>
662 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
666 // Destructible and constructible type properties.
669 struct add_rvalue_reference;
672 * @brief Utility to simplify expressions used in unevaluated operands
675 template<typename _Tp>
676 typename add_rvalue_reference<_Tp>::type declval() noexcept;
678 template<typename, unsigned = 0>
682 struct remove_all_extents;
684 template<typename _Tp>
685 struct __is_array_known_bounds
686 : public integral_constant<bool, (extent<_Tp>::value > 0)>
689 template<typename _Tp>
690 struct __is_array_unknown_bounds
691 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
694 // In N3290 is_destructible does not say anything about function
695 // types and abstract types, see LWG 2049. This implementation
696 // describes function types as non-destructible and all complete
697 // object types as destructible, iff the explicit destructor
698 // call expression is wellformed.
699 struct __do_is_destructible_impl
701 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
702 static true_type __test(int);
705 static false_type __test(...);
708 template<typename _Tp>
709 struct __is_destructible_impl
710 : public __do_is_destructible_impl
712 typedef decltype(__test<_Tp>(0)) type;
715 template<typename _Tp,
716 bool = __or_<is_void<_Tp>,
717 __is_array_unknown_bounds<_Tp>,
718 is_function<_Tp>>::value,
719 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
720 struct __is_destructible_safe;
722 template<typename _Tp>
723 struct __is_destructible_safe<_Tp, false, false>
724 : public __is_destructible_impl<typename
725 remove_all_extents<_Tp>::type>::type
728 template<typename _Tp>
729 struct __is_destructible_safe<_Tp, true, false>
730 : public false_type { };
732 template<typename _Tp>
733 struct __is_destructible_safe<_Tp, false, true>
734 : public true_type { };
737 template<typename _Tp>
738 struct is_destructible
739 : public __is_destructible_safe<_Tp>::type
742 // is_nothrow_destructible requires that is_destructible is
743 // satisfied as well. We realize that by mimicing the
744 // implementation of is_destructible but refer to noexcept(expr)
745 // instead of decltype(expr).
746 struct __do_is_nt_destructible_impl
748 template<typename _Tp>
749 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
753 static false_type __test(...);
756 template<typename _Tp>
757 struct __is_nt_destructible_impl
758 : public __do_is_nt_destructible_impl
760 typedef decltype(__test<_Tp>(0)) type;
763 template<typename _Tp,
764 bool = __or_<is_void<_Tp>,
765 __is_array_unknown_bounds<_Tp>,
766 is_function<_Tp>>::value,
767 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
768 struct __is_nt_destructible_safe;
770 template<typename _Tp>
771 struct __is_nt_destructible_safe<_Tp, false, false>
772 : public __is_nt_destructible_impl<typename
773 remove_all_extents<_Tp>::type>::type
776 template<typename _Tp>
777 struct __is_nt_destructible_safe<_Tp, true, false>
778 : public false_type { };
780 template<typename _Tp>
781 struct __is_nt_destructible_safe<_Tp, false, true>
782 : public true_type { };
784 /// is_nothrow_destructible
785 template<typename _Tp>
786 struct is_nothrow_destructible
787 : public __is_nt_destructible_safe<_Tp>::type
790 struct __do_is_default_constructible_impl
792 template<typename _Tp, typename = decltype(_Tp())>
793 static true_type __test(int);
796 static false_type __test(...);
799 template<typename _Tp>
800 struct __is_default_constructible_impl
801 : public __do_is_default_constructible_impl
803 typedef decltype(__test<_Tp>(0)) type;
806 template<typename _Tp>
807 struct __is_default_constructible_atom
808 : public __and_<__not_<is_void<_Tp>>,
809 __is_default_constructible_impl<_Tp>>::type
812 template<typename _Tp, bool = is_array<_Tp>::value>
813 struct __is_default_constructible_safe;
815 // The following technique is a workaround for a current core language
816 // restriction, which does not allow for array types to occur in
817 // functional casts of the form T(). Complete arrays can be default-
818 // constructed, if the element type is default-constructible, but
819 // arrays with unknown bounds are not.
820 template<typename _Tp>
821 struct __is_default_constructible_safe<_Tp, true>
822 : public __and_<__is_array_known_bounds<_Tp>,
823 __is_default_constructible_atom<typename
824 remove_all_extents<_Tp>::type>>::type
827 template<typename _Tp>
828 struct __is_default_constructible_safe<_Tp, false>
829 : public __is_default_constructible_atom<_Tp>::type
832 /// is_default_constructible
833 template<typename _Tp>
834 struct is_default_constructible
835 : public __is_default_constructible_safe<_Tp>::type
839 // Implementation of is_constructible.
841 // The hardest part of this trait is the binary direct-initialization
842 // case, because we hit into a functional cast of the form T(arg).
843 // This implementation uses different strategies depending on the
844 // target type to reduce the test overhead as much as possible:
846 // a) For a reference target type, we use a static_cast expression
847 // modulo its extra cases.
849 // b) For a non-reference target type we use a ::new expression.
850 struct __do_is_static_castable_impl
852 template<typename _From, typename _To, typename
853 = decltype(static_cast<_To>(declval<_From>()))>
854 static true_type __test(int);
856 template<typename, typename>
857 static false_type __test(...);
860 template<typename _From, typename _To>
861 struct __is_static_castable_impl
862 : public __do_is_static_castable_impl
864 typedef decltype(__test<_From, _To>(0)) type;
867 template<typename _From, typename _To>
868 struct __is_static_castable_safe
869 : public __is_static_castable_impl<_From, _To>::type
872 // __is_static_castable
873 template<typename _From, typename _To>
874 struct __is_static_castable
875 : public integral_constant<bool, (__is_static_castable_safe<
879 // Implementation for non-reference types. To meet the proper
880 // variable definition semantics, we also need to test for
881 // is_destructible in this case.
882 // This form should be simplified by a single expression:
883 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
884 struct __do_is_direct_constructible_impl
886 template<typename _Tp, typename _Arg, typename
887 = decltype(::new _Tp(declval<_Arg>()))>
888 static true_type __test(int);
890 template<typename, typename>
891 static false_type __test(...);
894 template<typename _Tp, typename _Arg>
895 struct __is_direct_constructible_impl
896 : public __do_is_direct_constructible_impl
898 typedef decltype(__test<_Tp, _Arg>(0)) type;
901 template<typename _Tp, typename _Arg>
902 struct __is_direct_constructible_new_safe
903 : public __and_<is_destructible<_Tp>,
904 __is_direct_constructible_impl<_Tp, _Arg>>::type
907 template<typename, typename>
910 template<typename, typename>
914 struct remove_reference;
916 template<typename _From, typename _To, bool
917 = __not_<__or_<is_void<_From>,
918 is_function<_From>>>::value>
919 struct __is_base_to_derived_ref;
921 // Detect whether we have a downcast situation during
922 // reference binding.
923 template<typename _From, typename _To>
924 struct __is_base_to_derived_ref<_From, _To, true>
926 typedef typename remove_cv<typename remove_reference<_From
927 >::type>::type __src_t;
928 typedef typename remove_cv<typename remove_reference<_To
929 >::type>::type __dst_t;
930 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
931 is_base_of<__src_t, __dst_t>> type;
932 static constexpr bool value = type::value;
935 template<typename _From, typename _To>
936 struct __is_base_to_derived_ref<_From, _To, false>
940 template<typename _From, typename _To, bool
941 = __and_<is_lvalue_reference<_From>,
942 is_rvalue_reference<_To>>::value>
943 struct __is_lvalue_to_rvalue_ref;
945 // Detect whether we have an lvalue of non-function type
946 // bound to a reference-compatible rvalue-reference.
947 template<typename _From, typename _To>
948 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
950 typedef typename remove_cv<typename remove_reference<
951 _From>::type>::type __src_t;
952 typedef typename remove_cv<typename remove_reference<
953 _To>::type>::type __dst_t;
954 typedef __and_<__not_<is_function<__src_t>>,
955 __or_<is_same<__src_t, __dst_t>,
956 is_base_of<__dst_t, __src_t>>> type;
957 static constexpr bool value = type::value;
960 template<typename _From, typename _To>
961 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
965 // Here we handle direct-initialization to a reference type as
966 // equivalent to a static_cast modulo overshooting conversions.
967 // These are restricted to the following conversions:
968 // a) A base class value to a derived class reference
969 // b) An lvalue to an rvalue-reference of reference-compatible
970 // types that are not functions
971 template<typename _Tp, typename _Arg>
972 struct __is_direct_constructible_ref_cast
973 : public __and_<__is_static_castable<_Arg, _Tp>,
974 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
975 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
979 template<typename _Tp, typename _Arg>
980 struct __is_direct_constructible_new
981 : public conditional<is_reference<_Tp>::value,
982 __is_direct_constructible_ref_cast<_Tp, _Arg>,
983 __is_direct_constructible_new_safe<_Tp, _Arg>
987 template<typename _Tp, typename _Arg>
988 struct __is_direct_constructible
989 : public __is_direct_constructible_new<_Tp, _Arg>::type
992 // Since default-construction and binary direct-initialization have
993 // been handled separately, the implementation of the remaining
994 // n-ary construction cases is rather straightforward. We can use
995 // here a functional cast, because array types are excluded anyway
996 // and this form is never interpreted as a C cast.
997 struct __do_is_nary_constructible_impl
999 template<typename _Tp, typename... _Args, typename
1000 = decltype(_Tp(declval<_Args>()...))>
1001 static true_type __test(int);
1003 template<typename, typename...>
1004 static false_type __test(...);
1007 template<typename _Tp, typename... _Args>
1008 struct __is_nary_constructible_impl
1009 : public __do_is_nary_constructible_impl
1011 typedef decltype(__test<_Tp, _Args...>(0)) type;
1014 template<typename _Tp, typename... _Args>
1015 struct __is_nary_constructible
1016 : public __is_nary_constructible_impl<_Tp, _Args...>::type
1018 static_assert(sizeof...(_Args) > 1,
1019 "Only useful for > 1 arguments");
1022 template<typename _Tp, typename... _Args>
1023 struct __is_constructible_impl
1024 : public __is_nary_constructible<_Tp, _Args...>
1027 template<typename _Tp, typename _Arg>
1028 struct __is_constructible_impl<_Tp, _Arg>
1029 : public __is_direct_constructible<_Tp, _Arg>
1032 template<typename _Tp>
1033 struct __is_constructible_impl<_Tp>
1034 : public is_default_constructible<_Tp>
1037 /// is_constructible
1038 template<typename _Tp, typename... _Args>
1039 struct is_constructible
1040 : public __is_constructible_impl<_Tp, _Args...>::type
1043 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1044 struct __is_copy_constructible_impl;
1046 template<typename _Tp>
1047 struct __is_copy_constructible_impl<_Tp, false>
1048 : public false_type { };
1050 template<typename _Tp>
1051 struct __is_copy_constructible_impl<_Tp, true>
1052 : public is_constructible<_Tp, const _Tp&>
1055 /// is_copy_constructible
1056 template<typename _Tp>
1057 struct is_copy_constructible
1058 : public __is_copy_constructible_impl<_Tp>
1061 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1062 struct __is_move_constructible_impl;
1064 template<typename _Tp>
1065 struct __is_move_constructible_impl<_Tp, false>
1066 : public false_type { };
1068 template<typename _Tp>
1069 struct __is_move_constructible_impl<_Tp, true>
1070 : public is_constructible<_Tp, _Tp&&>
1073 /// is_move_constructible
1074 template<typename _Tp>
1075 struct is_move_constructible
1076 : public __is_move_constructible_impl<_Tp>
1079 template<typename _Tp>
1080 struct __is_nt_default_constructible_atom
1081 : public integral_constant<bool, noexcept(_Tp())>
1084 template<typename _Tp, bool = is_array<_Tp>::value>
1085 struct __is_nt_default_constructible_impl;
1087 template<typename _Tp>
1088 struct __is_nt_default_constructible_impl<_Tp, true>
1089 : public __and_<__is_array_known_bounds<_Tp>,
1090 __is_nt_default_constructible_atom<typename
1091 remove_all_extents<_Tp>::type>>::type
1094 template<typename _Tp>
1095 struct __is_nt_default_constructible_impl<_Tp, false>
1096 : public __is_nt_default_constructible_atom<_Tp>
1099 /// is_nothrow_default_constructible
1100 template<typename _Tp>
1101 struct is_nothrow_default_constructible
1102 : public __and_<is_default_constructible<_Tp>,
1103 __is_nt_default_constructible_impl<_Tp>>::type
1106 template<typename _Tp, typename... _Args>
1107 struct __is_nt_constructible_impl
1108 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1111 template<typename _Tp, typename _Arg>
1112 struct __is_nt_constructible_impl<_Tp, _Arg>
1113 : public integral_constant<bool,
1114 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1117 template<typename _Tp>
1118 struct __is_nt_constructible_impl<_Tp>
1119 : public is_nothrow_default_constructible<_Tp>
1122 /// is_nothrow_constructible
1123 template<typename _Tp, typename... _Args>
1124 struct is_nothrow_constructible
1125 : public __and_<is_constructible<_Tp, _Args...>,
1126 __is_nt_constructible_impl<_Tp, _Args...>>::type
1129 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1130 struct __is_nothrow_copy_constructible_impl;
1132 template<typename _Tp>
1133 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1134 : public false_type { };
1136 template<typename _Tp>
1137 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1138 : public is_nothrow_constructible<_Tp, const _Tp&>
1141 /// is_nothrow_copy_constructible
1142 template<typename _Tp>
1143 struct is_nothrow_copy_constructible
1144 : public __is_nothrow_copy_constructible_impl<_Tp>
1147 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1148 struct __is_nothrow_move_constructible_impl;
1150 template<typename _Tp>
1151 struct __is_nothrow_move_constructible_impl<_Tp, false>
1152 : public false_type { };
1154 template<typename _Tp>
1155 struct __is_nothrow_move_constructible_impl<_Tp, true>
1156 : public is_nothrow_constructible<_Tp, _Tp&&>
1159 /// is_nothrow_move_constructible
1160 template<typename _Tp>
1161 struct is_nothrow_move_constructible
1162 : public __is_nothrow_move_constructible_impl<_Tp>
1165 template<typename _Tp, typename _Up>
1166 class __is_assignable_helper
1168 template<typename _Tp1, typename _Up1,
1169 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1173 template<typename, typename>
1178 typedef decltype(__test<_Tp, _Up>(0)) type;
1182 template<typename _Tp, typename _Up>
1183 struct is_assignable
1184 : public __is_assignable_helper<_Tp, _Up>::type
1187 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1188 struct __is_copy_assignable_impl;
1190 template<typename _Tp>
1191 struct __is_copy_assignable_impl<_Tp, false>
1192 : public false_type { };
1194 template<typename _Tp>
1195 struct __is_copy_assignable_impl<_Tp, true>
1196 : public is_assignable<_Tp&, const _Tp&>
1199 /// is_copy_assignable
1200 template<typename _Tp>
1201 struct is_copy_assignable
1202 : public __is_copy_assignable_impl<_Tp>
1205 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1206 struct __is_move_assignable_impl;
1208 template<typename _Tp>
1209 struct __is_move_assignable_impl<_Tp, false>
1210 : public false_type { };
1212 template<typename _Tp>
1213 struct __is_move_assignable_impl<_Tp, true>
1214 : public is_assignable<_Tp&, _Tp&&>
1217 /// is_move_assignable
1218 template<typename _Tp>
1219 struct is_move_assignable
1220 : public __is_move_assignable_impl<_Tp>
1223 template<typename _Tp, typename _Up>
1224 struct __is_nt_assignable_impl
1225 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1228 /// is_nothrow_assignable
1229 template<typename _Tp, typename _Up>
1230 struct is_nothrow_assignable
1231 : public __and_<is_assignable<_Tp, _Up>,
1232 __is_nt_assignable_impl<_Tp, _Up>>::type
1235 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1236 struct __is_nt_copy_assignable_impl;
1238 template<typename _Tp>
1239 struct __is_nt_copy_assignable_impl<_Tp, false>
1240 : public false_type { };
1242 template<typename _Tp>
1243 struct __is_nt_copy_assignable_impl<_Tp, true>
1244 : public is_nothrow_assignable<_Tp&, const _Tp&>
1247 /// is_nothrow_copy_assignable
1248 template<typename _Tp>
1249 struct is_nothrow_copy_assignable
1250 : public __is_nt_copy_assignable_impl<_Tp>
1253 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1254 struct __is_nt_move_assignable_impl;
1256 template<typename _Tp>
1257 struct __is_nt_move_assignable_impl<_Tp, false>
1258 : public false_type { };
1260 template<typename _Tp>
1261 struct __is_nt_move_assignable_impl<_Tp, true>
1262 : public is_nothrow_assignable<_Tp&, _Tp&&>
1265 /// is_nothrow_move_assignable
1266 template<typename _Tp>
1267 struct is_nothrow_move_assignable
1268 : public __is_nt_move_assignable_impl<_Tp>
1271 /// is_trivially_constructible (still unimplemented)
1273 /// is_trivially_default_constructible (still unimplemented)
1275 /// is_trivially_copy_constructible (still unimplemented)
1277 /// is_trivially_move_constructible (still unimplemented)
1279 /// is_trivially_assignable (still unimplemented)
1281 /// is_trivially_copy_assignable (still unimplemented)
1283 /// is_trivially_move_assignable (still unimplemented)
1285 /// is_trivially_destructible
1286 template<typename _Tp>
1287 struct is_trivially_destructible
1288 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1289 __has_trivial_destructor(_Tp)>>::type
1292 /// has_trivial_default_constructor (temporary legacy)
1293 template<typename _Tp>
1294 struct has_trivial_default_constructor
1295 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1298 /// has_trivial_copy_constructor (temporary legacy)
1299 template<typename _Tp>
1300 struct has_trivial_copy_constructor
1301 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1304 /// has_trivial_copy_assign (temporary legacy)
1305 template<typename _Tp>
1306 struct has_trivial_copy_assign
1307 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1310 /// has_virtual_destructor
1311 template<typename _Tp>
1312 struct has_virtual_destructor
1313 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1317 // type property queries.
1320 template<typename _Tp>
1322 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1327 : public integral_constant<std::size_t, 0> { };
1329 template<typename _Tp, std::size_t _Size>
1330 struct rank<_Tp[_Size]>
1331 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1333 template<typename _Tp>
1335 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1338 template<typename, unsigned _Uint>
1340 : public integral_constant<std::size_t, 0> { };
1342 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1343 struct extent<_Tp[_Size], _Uint>
1344 : public integral_constant<std::size_t,
1345 _Uint == 0 ? _Size : extent<_Tp,
1349 template<typename _Tp, unsigned _Uint>
1350 struct extent<_Tp[], _Uint>
1351 : public integral_constant<std::size_t,
1352 _Uint == 0 ? 0 : extent<_Tp,
1360 template<typename, typename>
1362 : public false_type { };
1364 template<typename _Tp>
1365 struct is_same<_Tp, _Tp>
1366 : public true_type { };
1369 template<typename _Base, typename _Derived>
1371 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1374 template<typename _From, typename _To,
1375 bool = __or_<is_void<_From>, is_function<_To>,
1376 is_array<_To>>::value>
1377 struct __is_convertible_helper
1378 { typedef typename is_void<_To>::type type; };
1380 template<typename _From, typename _To>
1381 class __is_convertible_helper<_From, _To, false>
1383 template<typename _To1>
1384 static void __test_aux(_To1);
1386 template<typename _From1, typename _To1,
1387 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1391 template<typename, typename>
1396 typedef decltype(__test<_From, _To>(0)) type;
1401 template<typename _From, typename _To>
1402 struct is_convertible
1403 : public __is_convertible_helper<_From, _To>::type
1407 // Const-volatile modifications.
1410 template<typename _Tp>
1412 { typedef _Tp type; };
1414 template<typename _Tp>
1415 struct remove_const<_Tp const>
1416 { typedef _Tp type; };
1419 template<typename _Tp>
1420 struct remove_volatile
1421 { typedef _Tp type; };
1423 template<typename _Tp>
1424 struct remove_volatile<_Tp volatile>
1425 { typedef _Tp type; };
1428 template<typename _Tp>
1432 remove_const<typename remove_volatile<_Tp>::type>::type type;
1436 template<typename _Tp>
1438 { typedef _Tp const type; };
1441 template<typename _Tp>
1443 { typedef _Tp volatile type; };
1446 template<typename _Tp>
1450 add_const<typename add_volatile<_Tp>::type>::type type;
1453 #if __cplusplus > 201103L
1454 /// Alias template for remove_const
1455 template<typename _Tp>
1456 using remove_const_t = typename remove_const<_Tp>::type;
1458 /// Alias template for remove_volatile
1459 template<typename _Tp>
1460 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1462 /// Alias template for remove_cv
1463 template<typename _Tp>
1464 using remove_cv_t = typename remove_cv<_Tp>::type;
1466 /// Alias template for add_const
1467 template<typename _Tp>
1468 using add_const_t = typename add_const<_Tp>::type;
1470 /// Alias template for add_volatile
1471 template<typename _Tp>
1472 using add_volatile_t = typename add_volatile<_Tp>::type;
1474 /// Alias template for add_cv
1475 template<typename _Tp>
1476 using add_cv_t = typename add_cv<_Tp>::type;
1479 // Reference transformations.
1481 /// remove_reference
1482 template<typename _Tp>
1483 struct remove_reference
1484 { typedef _Tp type; };
1486 template<typename _Tp>
1487 struct remove_reference<_Tp&>
1488 { typedef _Tp type; };
1490 template<typename _Tp>
1491 struct remove_reference<_Tp&&>
1492 { typedef _Tp type; };
1494 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1495 struct __add_lvalue_reference_helper
1496 { typedef _Tp type; };
1498 template<typename _Tp>
1499 struct __add_lvalue_reference_helper<_Tp, true>
1500 { typedef _Tp& type; };
1502 /// add_lvalue_reference
1503 template<typename _Tp>
1504 struct add_lvalue_reference
1505 : public __add_lvalue_reference_helper<_Tp>
1508 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1509 struct __add_rvalue_reference_helper
1510 { typedef _Tp type; };
1512 template<typename _Tp>
1513 struct __add_rvalue_reference_helper<_Tp, true>
1514 { typedef _Tp&& type; };
1516 /// add_rvalue_reference
1517 template<typename _Tp>
1518 struct add_rvalue_reference
1519 : public __add_rvalue_reference_helper<_Tp>
1522 #if __cplusplus > 201103L
1523 /// Alias template for remove_reference
1524 template<typename _Tp>
1525 using remove_reference_t = typename remove_reference<_Tp>::type;
1527 /// Alias template for add_lvalue_reference
1528 template<typename _Tp>
1529 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1531 /// Alias template for add_rvalue_reference
1532 template<typename _Tp>
1533 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1536 // Sign modifications.
1538 // Utility for constructing identically cv-qualified types.
1539 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1540 struct __cv_selector;
1542 template<typename _Unqualified>
1543 struct __cv_selector<_Unqualified, false, false>
1544 { typedef _Unqualified __type; };
1546 template<typename _Unqualified>
1547 struct __cv_selector<_Unqualified, false, true>
1548 { typedef volatile _Unqualified __type; };
1550 template<typename _Unqualified>
1551 struct __cv_selector<_Unqualified, true, false>
1552 { typedef const _Unqualified __type; };
1554 template<typename _Unqualified>
1555 struct __cv_selector<_Unqualified, true, true>
1556 { typedef const volatile _Unqualified __type; };
1558 template<typename _Qualified, typename _Unqualified,
1559 bool _IsConst = is_const<_Qualified>::value,
1560 bool _IsVol = is_volatile<_Qualified>::value>
1561 class __match_cv_qualifiers
1563 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1566 typedef typename __match::__type __type;
1569 // Utility for finding the unsigned versions of signed integral types.
1570 template<typename _Tp>
1571 struct __make_unsigned
1572 { typedef _Tp __type; };
1575 struct __make_unsigned<char>
1576 { typedef unsigned char __type; };
1579 struct __make_unsigned<signed char>
1580 { typedef unsigned char __type; };
1583 struct __make_unsigned<short>
1584 { typedef unsigned short __type; };
1587 struct __make_unsigned<int>
1588 { typedef unsigned int __type; };
1591 struct __make_unsigned<long>
1592 { typedef unsigned long __type; };
1595 struct __make_unsigned<long long>
1596 { typedef unsigned long long __type; };
1598 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1600 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1604 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1606 struct __make_unsigned<__int128>
1607 { typedef unsigned __int128 __type; };
1610 // Select between integral and enum: not possible to be both.
1611 template<typename _Tp,
1612 bool _IsInt = is_integral<_Tp>::value,
1613 bool _IsEnum = is_enum<_Tp>::value>
1614 class __make_unsigned_selector;
1616 template<typename _Tp>
1617 class __make_unsigned_selector<_Tp, true, false>
1619 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1620 typedef typename __unsignedt::__type __unsigned_type;
1621 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1624 typedef typename __cv_unsigned::__type __type;
1627 template<typename _Tp>
1628 class __make_unsigned_selector<_Tp, false, true>
1630 // With -fshort-enums, an enum may be as small as a char.
1631 typedef unsigned char __smallest;
1632 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1633 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1634 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1635 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1636 typedef typename __cond2::type __cond2_type;
1637 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1638 typedef typename __cond1::type __cond1_type;
1641 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1644 // Given an integral/enum type, return the corresponding unsigned
1646 // Primary template.
1648 template<typename _Tp>
1649 struct make_unsigned
1650 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1652 // Integral, but don't define.
1654 struct make_unsigned<bool>;
1657 // Utility for finding the signed versions of unsigned integral types.
1658 template<typename _Tp>
1659 struct __make_signed
1660 { typedef _Tp __type; };
1663 struct __make_signed<char>
1664 { typedef signed char __type; };
1667 struct __make_signed<unsigned char>
1668 { typedef signed char __type; };
1671 struct __make_signed<unsigned short>
1672 { typedef signed short __type; };
1675 struct __make_signed<unsigned int>
1676 { typedef signed int __type; };
1679 struct __make_signed<unsigned long>
1680 { typedef signed long __type; };
1683 struct __make_signed<unsigned long long>
1684 { typedef signed long long __type; };
1686 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1688 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1692 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1694 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1697 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1701 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1703 struct __make_signed<unsigned __int128>
1704 { typedef __int128 __type; };
1707 // Select between integral and enum: not possible to be both.
1708 template<typename _Tp,
1709 bool _IsInt = is_integral<_Tp>::value,
1710 bool _IsEnum = is_enum<_Tp>::value>
1711 class __make_signed_selector;
1713 template<typename _Tp>
1714 class __make_signed_selector<_Tp, true, false>
1716 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1717 typedef typename __signedt::__type __signed_type;
1718 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1721 typedef typename __cv_signed::__type __type;
1724 template<typename _Tp>
1725 class __make_signed_selector<_Tp, false, true>
1727 // With -fshort-enums, an enum may be as small as a char.
1728 typedef signed char __smallest;
1729 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1730 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1731 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1732 typedef conditional<__b2, signed int, signed long> __cond2;
1733 typedef typename __cond2::type __cond2_type;
1734 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1735 typedef typename __cond1::type __cond1_type;
1738 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1741 // Given an integral/enum type, return the corresponding signed
1743 // Primary template.
1745 template<typename _Tp>
1747 { typedef typename __make_signed_selector<_Tp>::__type type; };
1749 // Integral, but don't define.
1751 struct make_signed<bool>;
1753 #if __cplusplus > 201103L
1754 /// Alias template for make_signed
1755 template<typename _Tp>
1756 using make_signed_t = typename make_signed<_Tp>::type;
1758 /// Alias template for make_unsigned
1759 template<typename _Tp>
1760 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1763 // Array modifications.
1766 template<typename _Tp>
1767 struct remove_extent
1768 { typedef _Tp type; };
1770 template<typename _Tp, std::size_t _Size>
1771 struct remove_extent<_Tp[_Size]>
1772 { typedef _Tp type; };
1774 template<typename _Tp>
1775 struct remove_extent<_Tp[]>
1776 { typedef _Tp type; };
1778 /// remove_all_extents
1779 template<typename _Tp>
1780 struct remove_all_extents
1781 { typedef _Tp type; };
1783 template<typename _Tp, std::size_t _Size>
1784 struct remove_all_extents<_Tp[_Size]>
1785 { typedef typename remove_all_extents<_Tp>::type type; };
1787 template<typename _Tp>
1788 struct remove_all_extents<_Tp[]>
1789 { typedef typename remove_all_extents<_Tp>::type type; };
1791 #if __cplusplus > 201103L
1792 /// Alias template for remove_extent
1793 template<typename _Tp>
1794 using remove_extent_t = typename remove_extent<_Tp>::type;
1796 /// Alias template for remove_all_extents
1797 template<typename _Tp>
1798 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1801 // Pointer modifications.
1803 template<typename _Tp, typename>
1804 struct __remove_pointer_helper
1805 { typedef _Tp type; };
1807 template<typename _Tp, typename _Up>
1808 struct __remove_pointer_helper<_Tp, _Up*>
1809 { typedef _Up type; };
1812 template<typename _Tp>
1813 struct remove_pointer
1814 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1818 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1819 is_void<_Tp>>::value>
1820 struct __add_pointer_helper
1821 { typedef _Tp type; };
1823 template<typename _Tp>
1824 struct __add_pointer_helper<_Tp, true>
1825 { typedef typename remove_reference<_Tp>::type* type; };
1827 template<typename _Tp>
1829 : public __add_pointer_helper<_Tp>
1832 #if __cplusplus > 201103L
1833 /// Alias template for remove_pointer
1834 template<typename _Tp>
1835 using remove_pointer_t = typename remove_pointer<_Tp>::type;
1837 /// Alias template for add_pointer
1838 template<typename _Tp>
1839 using add_pointer_t = typename add_pointer<_Tp>::type;
1842 template<std::size_t _Len>
1843 struct __aligned_storage_msa
1847 unsigned char __data[_Len];
1848 struct __attribute__((__aligned__)) { } __align;
1853 * @brief Alignment type.
1855 * The value of _Align is a default-alignment which shall be the
1856 * most stringent alignment requirement for any C++ object type
1857 * whose size is no greater than _Len (3.9). The member typedef
1858 * type shall be a POD type suitable for use as uninitialized
1859 * storage for any object whose size is at most _Len and whose
1860 * alignment is a divisor of _Align.
1862 template<std::size_t _Len, std::size_t _Align =
1863 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1864 struct aligned_storage
1868 unsigned char __data[_Len];
1869 struct __attribute__((__aligned__((_Align)))) { } __align;
1874 // Decay trait for arrays and functions, used for perfect forwarding
1875 // in make_pair, make_tuple, etc.
1876 template<typename _Up,
1877 bool _IsArray = is_array<_Up>::value,
1878 bool _IsFunction = is_function<_Up>::value>
1879 struct __decay_selector;
1882 template<typename _Up>
1883 struct __decay_selector<_Up, false, false>
1884 { typedef typename remove_cv<_Up>::type __type; };
1886 template<typename _Up>
1887 struct __decay_selector<_Up, true, false>
1888 { typedef typename remove_extent<_Up>::type* __type; };
1890 template<typename _Up>
1891 struct __decay_selector<_Up, false, true>
1892 { typedef typename add_pointer<_Up>::type __type; };
1895 template<typename _Tp>
1898 typedef typename remove_reference<_Tp>::type __remove_type;
1901 typedef typename __decay_selector<__remove_type>::__type type;
1904 template<typename _Tp>
1905 class reference_wrapper;
1907 // Helper which adds a reference to a type when given a reference_wrapper
1908 template<typename _Tp>
1909 struct __strip_reference_wrapper
1914 template<typename _Tp>
1915 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1917 typedef _Tp& __type;
1920 template<typename _Tp>
1921 struct __decay_and_strip
1923 typedef typename __strip_reference_wrapper<
1924 typename decay<_Tp>::type>::__type __type;
1928 // Primary template.
1929 /// Define a member typedef @c type only if a boolean constant is true.
1930 template<bool, typename _Tp = void>
1934 // Partial specialization for true.
1935 template<typename _Tp>
1936 struct enable_if<true, _Tp>
1937 { typedef _Tp type; };
1939 template<typename... _Cond>
1940 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
1942 // Primary template.
1943 /// Define a member typedef @c type to one of two argument types.
1944 template<bool _Cond, typename _Iftrue, typename _Iffalse>
1946 { typedef _Iftrue type; };
1948 // Partial specialization for false.
1949 template<typename _Iftrue, typename _Iffalse>
1950 struct conditional<false, _Iftrue, _Iffalse>
1951 { typedef _Iffalse type; };
1954 template<typename... _Tp>
1957 // Sfinae-friendly common_type implementation:
1959 struct __do_common_type_impl
1961 template<typename _Tp, typename _Up>
1962 static __success_type<typename decay<decltype
1963 (true ? std::declval<_Tp>()
1964 : std::declval<_Up>())>::type> _S_test(int);
1966 template<typename, typename>
1967 static __failure_type _S_test(...);
1970 template<typename _Tp, typename _Up>
1971 struct __common_type_impl
1972 : private __do_common_type_impl
1974 typedef decltype(_S_test<_Tp, _Up>(0)) type;
1977 struct __do_member_type_wrapper
1979 template<typename _Tp>
1980 static __success_type<typename _Tp::type> _S_test(int);
1983 static __failure_type _S_test(...);
1986 template<typename _Tp>
1987 struct __member_type_wrapper
1988 : private __do_member_type_wrapper
1990 typedef decltype(_S_test<_Tp>(0)) type;
1993 template<typename _CTp, typename... _Args>
1994 struct __expanded_common_type_wrapper
1996 typedef common_type<typename _CTp::type, _Args...> type;
1999 template<typename... _Args>
2000 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2001 { typedef __failure_type type; };
2003 template<typename _Tp>
2004 struct common_type<_Tp>
2005 { typedef typename decay<_Tp>::type type; };
2007 template<typename _Tp, typename _Up>
2008 struct common_type<_Tp, _Up>
2009 : public __common_type_impl<_Tp, _Up>::type
2012 template<typename _Tp, typename _Up, typename... _Vp>
2013 struct common_type<_Tp, _Up, _Vp...>
2014 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2015 common_type<_Tp, _Up>>::type, _Vp...>::type
2018 /// The underlying type of an enum.
2019 template<typename _Tp>
2020 struct underlying_type
2022 typedef __underlying_type(_Tp) type;
2025 template<typename _Tp>
2026 struct __declval_protector
2028 static const bool __stop = false;
2029 static typename add_rvalue_reference<_Tp>::type __delegate();
2032 template<typename _Tp>
2033 inline typename add_rvalue_reference<_Tp>::type
2036 static_assert(__declval_protector<_Tp>::__stop,
2037 "declval() must not be used!");
2038 return __declval_protector<_Tp>::__delegate();
2042 template<typename _Signature>
2045 // Sfinae-friendly result_of implementation:
2047 // [func.require] paragraph 1 bullet 1:
2048 struct __result_of_memfun_ref_impl
2050 template<typename _Fp, typename _Tp1, typename... _Args>
2051 static __success_type<decltype(
2052 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2055 template<typename...>
2056 static __failure_type _S_test(...);
2059 template<typename _MemPtr, typename _Arg, typename... _Args>
2060 struct __result_of_memfun_ref
2061 : private __result_of_memfun_ref_impl
2063 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2066 // [func.require] paragraph 1 bullet 2:
2067 struct __result_of_memfun_deref_impl
2069 template<typename _Fp, typename _Tp1, typename... _Args>
2070 static __success_type<decltype(
2071 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2074 template<typename...>
2075 static __failure_type _S_test(...);
2078 template<typename _MemPtr, typename _Arg, typename... _Args>
2079 struct __result_of_memfun_deref
2080 : private __result_of_memfun_deref_impl
2082 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2085 // [func.require] paragraph 1 bullet 3:
2086 struct __result_of_memobj_ref_impl
2088 template<typename _Fp, typename _Tp1>
2089 static __success_type<decltype(
2090 std::declval<_Tp1>().*std::declval<_Fp>()
2093 template<typename, typename>
2094 static __failure_type _S_test(...);
2097 template<typename _MemPtr, typename _Arg>
2098 struct __result_of_memobj_ref
2099 : private __result_of_memobj_ref_impl
2101 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2104 // [func.require] paragraph 1 bullet 4:
2105 struct __result_of_memobj_deref_impl
2107 template<typename _Fp, typename _Tp1>
2108 static __success_type<decltype(
2109 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2112 template<typename, typename>
2113 static __failure_type _S_test(...);
2116 template<typename _MemPtr, typename _Arg>
2117 struct __result_of_memobj_deref
2118 : private __result_of_memobj_deref_impl
2120 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2123 template<typename _MemPtr, typename _Arg>
2124 struct __result_of_memobj;
2126 template<typename _Res, typename _Class, typename _Arg>
2127 struct __result_of_memobj<_Res _Class::*, _Arg>
2129 typedef typename remove_cv<typename remove_reference<
2130 _Arg>::type>::type _Argval;
2131 typedef _Res _Class::* _MemPtr;
2132 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2133 is_base_of<_Class, _Argval>>::value,
2134 __result_of_memobj_ref<_MemPtr, _Arg>,
2135 __result_of_memobj_deref<_MemPtr, _Arg>
2139 template<typename _MemPtr, typename _Arg, typename... _Args>
2140 struct __result_of_memfun;
2142 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2143 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2145 typedef typename remove_cv<typename remove_reference<
2146 _Arg>::type>::type _Argval;
2147 typedef _Res _Class::* _MemPtr;
2148 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2149 is_base_of<_Class, _Argval>>::value,
2150 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2151 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2155 template<bool, bool, typename _Functor, typename... _ArgTypes>
2156 struct __result_of_impl
2158 typedef __failure_type type;
2161 template<typename _MemPtr, typename _Arg>
2162 struct __result_of_impl<true, false, _MemPtr, _Arg>
2163 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2166 template<typename _MemPtr, typename _Arg, typename... _Args>
2167 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2168 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2171 // [func.require] paragraph 1 bullet 5:
2172 struct __result_of_other_impl
2174 template<typename _Fn, typename... _Args>
2175 static __success_type<decltype(
2176 std::declval<_Fn>()(std::declval<_Args>()...)
2179 template<typename...>
2180 static __failure_type _S_test(...);
2183 template<typename _Functor, typename... _ArgTypes>
2184 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2185 : private __result_of_other_impl
2187 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2190 template<typename _Functor, typename... _ArgTypes>
2191 struct result_of<_Functor(_ArgTypes...)>
2192 : public __result_of_impl<
2193 is_member_object_pointer<
2194 typename remove_reference<_Functor>::type
2196 is_member_function_pointer<
2197 typename remove_reference<_Functor>::type
2199 _Functor, _ArgTypes...
2203 #if __cplusplus > 201103L
2204 /// Alias template for aligned_storage
2205 template<size_t _Len, size_t _Align =
2206 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2207 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2209 /// Alias template for decay
2210 template<typename _Tp>
2211 using decay_t = typename decay<_Tp>::type;
2213 /// Alias template for enable_if
2214 template<bool _Cond, typename _Tp = void>
2215 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2217 /// Alias template for conditional
2218 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2219 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2221 /// Alias template for common_type
2222 template<typename... _Tp>
2223 using common_type_t = typename common_type<_Tp...>::type;
2225 /// Alias template for underlying_type
2226 template<typename _Tp>
2227 using underlying_type_t = typename underlying_type<_Tp>::type;
2229 /// Alias template for result_of
2230 template<typename _Tp>
2231 using result_of_t = typename result_of<_Tp>::type;
2234 /// @} group metaprogramming
2237 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2238 * member type _NTYPE.
2240 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2241 template<typename _Tp> \
2242 class __has_##_NTYPE##_helper \
2244 template<typename _Up> \
2248 template<typename _Up> \
2249 static true_type __test(_Wrap_type<typename _Up::_NTYPE>*); \
2251 template<typename _Up> \
2252 static false_type __test(...); \
2255 typedef decltype(__test<_Tp>(0)) type; \
2258 template<typename _Tp> \
2259 struct __has_##_NTYPE \
2260 : public __has_##_NTYPE##_helper \
2261 <typename remove_cv<_Tp>::type>::type \
2264 _GLIBCXX_END_NAMESPACE_VERSION
2269 #endif // _GLIBCXX_TYPE_TRAITS