1 // C++0x type_traits -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011 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 #ifndef __GXX_EXPERIMENTAL_CXX0X__
35 # include <bits/c++0x_warning.h>
38 #include <bits/c++config.h>
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 * @addtogroup metaprogramming
51 typedef struct { char __arr[2]; } __two;
54 // Meta programming helper types.
56 template<bool, typename, typename>
59 template<typename _Tp, _Tp>
60 struct integral_constant;
62 template<typename, typename, typename...>
65 template<typename _B1, typename _B2>
66 struct __or_<_B1, _B2>
67 : public conditional<_B1::value, _B1, _B2>::type
70 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
71 struct __or_<_B1, _B2, _B3, _Bn...>
72 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
75 template<typename, typename, typename...>
78 template<typename _B1, typename _B2>
79 struct __and_<_B1, _B2>
80 : public conditional<_B1::value, _B2, _B1>::type
83 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
84 struct __and_<_B1, _B2, _B3, _Bn...>
85 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
88 template<typename _Pp>
90 : public integral_constant<bool, !_Pp::value>
96 template<typename _Tp, _Tp __v>
97 struct integral_constant
99 static constexpr _Tp value = __v;
100 typedef _Tp value_type;
101 typedef integral_constant<_Tp, __v> type;
102 constexpr operator value_type() { return value; }
105 /// typedef for true_type
106 typedef integral_constant<bool, true> true_type;
108 /// typedef for false_type
109 typedef integral_constant<bool, false> false_type;
111 template<typename _Tp, _Tp __v>
112 constexpr _Tp integral_constant<_Tp, __v>::value;
114 // primary type categories.
120 struct __is_void_helper
121 : public false_type { };
124 struct __is_void_helper<void>
125 : public true_type { };
128 template<typename _Tp>
130 : public integral_constant<bool, (__is_void_helper<typename
131 remove_cv<_Tp>::type>::value)>
135 struct __is_integral_helper
136 : public false_type { };
139 struct __is_integral_helper<bool>
140 : public true_type { };
143 struct __is_integral_helper<char>
144 : public true_type { };
147 struct __is_integral_helper<signed char>
148 : public true_type { };
151 struct __is_integral_helper<unsigned char>
152 : public true_type { };
154 #ifdef _GLIBCXX_USE_WCHAR_T
156 struct __is_integral_helper<wchar_t>
157 : public true_type { };
161 struct __is_integral_helper<char16_t>
162 : public true_type { };
165 struct __is_integral_helper<char32_t>
166 : public true_type { };
169 struct __is_integral_helper<short>
170 : public true_type { };
173 struct __is_integral_helper<unsigned short>
174 : public true_type { };
177 struct __is_integral_helper<int>
178 : public true_type { };
181 struct __is_integral_helper<unsigned int>
182 : public true_type { };
185 struct __is_integral_helper<long>
186 : public true_type { };
189 struct __is_integral_helper<unsigned long>
190 : public true_type { };
193 struct __is_integral_helper<long long>
194 : public true_type { };
197 struct __is_integral_helper<unsigned long long>
198 : public true_type { };
201 template<typename _Tp>
203 : public integral_constant<bool, (__is_integral_helper<typename
204 remove_cv<_Tp>::type>::value)>
208 struct __is_floating_point_helper
209 : public false_type { };
212 struct __is_floating_point_helper<float>
213 : public true_type { };
216 struct __is_floating_point_helper<double>
217 : public true_type { };
220 struct __is_floating_point_helper<long double>
221 : public true_type { };
223 /// is_floating_point
224 template<typename _Tp>
225 struct is_floating_point
226 : public integral_constant<bool, (__is_floating_point_helper<typename
227 remove_cv<_Tp>::type>::value)>
233 : public false_type { };
235 template<typename _Tp, std::size_t _Size>
236 struct is_array<_Tp[_Size]>
237 : public true_type { };
239 template<typename _Tp>
240 struct is_array<_Tp[]>
241 : public true_type { };
244 struct __is_pointer_helper
245 : public false_type { };
247 template<typename _Tp>
248 struct __is_pointer_helper<_Tp*>
249 : public true_type { };
252 template<typename _Tp>
254 : public integral_constant<bool, (__is_pointer_helper<typename
255 remove_cv<_Tp>::type>::value)>
258 /// is_lvalue_reference
260 struct is_lvalue_reference
261 : public false_type { };
263 template<typename _Tp>
264 struct is_lvalue_reference<_Tp&>
265 : public true_type { };
267 /// is_rvalue_reference
269 struct is_rvalue_reference
270 : public false_type { };
272 template<typename _Tp>
273 struct is_rvalue_reference<_Tp&&>
274 : public true_type { };
280 struct __is_member_object_pointer_helper
281 : public false_type { };
283 template<typename _Tp, typename _Cp>
284 struct __is_member_object_pointer_helper<_Tp _Cp::*>
285 : public integral_constant<bool, !is_function<_Tp>::value> { };
287 /// is_member_object_pointer
288 template<typename _Tp>
289 struct is_member_object_pointer
290 : public integral_constant<bool, (__is_member_object_pointer_helper<
291 typename remove_cv<_Tp>::type>::value)>
295 struct __is_member_function_pointer_helper
296 : public false_type { };
298 template<typename _Tp, typename _Cp>
299 struct __is_member_function_pointer_helper<_Tp _Cp::*>
300 : public integral_constant<bool, is_function<_Tp>::value> { };
302 /// is_member_function_pointer
303 template<typename _Tp>
304 struct is_member_function_pointer
305 : public integral_constant<bool, (__is_member_function_pointer_helper<
306 typename remove_cv<_Tp>::type>::value)>
310 template<typename _Tp>
312 : public integral_constant<bool, __is_enum(_Tp)>
316 template<typename _Tp>
318 : public integral_constant<bool, __is_union(_Tp)>
322 template<typename _Tp>
324 : public integral_constant<bool, __is_class(_Tp)>
330 : public false_type { };
332 template<typename _Res, typename... _ArgTypes>
333 struct is_function<_Res(_ArgTypes...)>
334 : public true_type { };
336 template<typename _Res, typename... _ArgTypes>
337 struct is_function<_Res(_ArgTypes......)>
338 : public true_type { };
340 template<typename _Res, typename... _ArgTypes>
341 struct is_function<_Res(_ArgTypes...) const>
342 : public true_type { };
344 template<typename _Res, typename... _ArgTypes>
345 struct is_function<_Res(_ArgTypes......) const>
346 : public true_type { };
348 template<typename _Res, typename... _ArgTypes>
349 struct is_function<_Res(_ArgTypes...) volatile>
350 : public true_type { };
352 template<typename _Res, typename... _ArgTypes>
353 struct is_function<_Res(_ArgTypes......) volatile>
354 : public true_type { };
356 template<typename _Res, typename... _ArgTypes>
357 struct is_function<_Res(_ArgTypes...) const volatile>
358 : public true_type { };
360 template<typename _Res, typename... _ArgTypes>
361 struct is_function<_Res(_ArgTypes......) const volatile>
362 : public true_type { };
365 struct __is_nullptr_t_helper
366 : public false_type { };
369 struct __is_nullptr_t_helper<std::nullptr_t>
370 : public true_type { };
372 // __is_nullptr_t (extension).
373 template<typename _Tp>
374 struct __is_nullptr_t
375 : public integral_constant<bool, (__is_nullptr_t_helper<typename
376 remove_cv<_Tp>::type>::value)>
379 // composite type categories.
382 template<typename _Tp>
384 : public __or_<is_lvalue_reference<_Tp>,
385 is_rvalue_reference<_Tp>>::type
389 template<typename _Tp>
391 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
395 template<typename _Tp>
396 struct is_fundamental
397 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>>::type
401 template<typename _Tp>
403 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
408 struct is_member_pointer;
411 template<typename _Tp>
413 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
414 is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type
418 template<typename _Tp>
420 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
422 /// is_member_pointer
423 template<typename _Tp>
424 struct __is_member_pointer_helper
425 : public false_type { };
427 template<typename _Tp, typename _Cp>
428 struct __is_member_pointer_helper<_Tp _Cp::*>
429 : public true_type { };
431 template<typename _Tp>
432 struct is_member_pointer
433 : public integral_constant<bool, (__is_member_pointer_helper<
434 typename remove_cv<_Tp>::type>::value)>
442 : public false_type { };
444 template<typename _Tp>
445 struct is_const<_Tp const>
446 : public true_type { };
451 : public false_type { };
453 template<typename _Tp>
454 struct is_volatile<_Tp volatile>
455 : public true_type { };
458 template<typename _Tp>
460 : public integral_constant<bool, __is_trivial(_Tp)>
463 /// is_trivially_copyable (still unimplemented)
465 /// is_standard_layout
466 template<typename _Tp>
467 struct is_standard_layout
468 : public integral_constant<bool, __is_standard_layout(_Tp)>
472 // Could use is_standard_layout && is_trivial instead of the builtin.
473 template<typename _Tp>
475 : public integral_constant<bool, __is_pod(_Tp)>
479 template<typename _Tp>
480 struct is_literal_type
481 : public integral_constant<bool, __is_literal_type(_Tp)>
485 template<typename _Tp>
487 : public integral_constant<bool, __is_empty(_Tp)>
491 template<typename _Tp>
492 struct is_polymorphic
493 : public integral_constant<bool, __is_polymorphic(_Tp)>
497 template<typename _Tp>
499 : public integral_constant<bool, __is_abstract(_Tp)>
502 template<typename _Tp,
503 bool = is_integral<_Tp>::value,
504 bool = is_floating_point<_Tp>::value>
505 struct __is_signed_helper
506 : public false_type { };
508 template<typename _Tp>
509 struct __is_signed_helper<_Tp, false, true>
510 : public true_type { };
512 template<typename _Tp>
513 struct __is_signed_helper<_Tp, true, false>
514 : public integral_constant<bool, static_cast<bool>(_Tp(-1) < _Tp(0))>
518 template<typename _Tp>
520 : public integral_constant<bool, __is_signed_helper<_Tp>::value>
524 template<typename _Tp>
526 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
530 // destructible and constructible type properties
533 struct add_rvalue_reference;
535 template<typename _Tp>
536 typename add_rvalue_reference<_Tp>::type declval() noexcept;
538 template<typename, unsigned = 0>
542 struct remove_all_extents;
544 template<typename _Tp>
545 struct __is_array_known_bounds
546 : public integral_constant<bool, (extent<_Tp>::value > 0)>
549 template<typename _Tp>
550 struct __is_array_unknown_bounds
551 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
554 struct __do_is_destructible_impl_1
556 template<typename _Up>
557 struct __w { _Up __u; };
559 template<typename _Tp, typename
560 = decltype(declval<__w<_Tp>&>().~__w<_Tp>())>
561 static true_type __test(int);
564 static false_type __test(...);
567 template<typename _Tp>
568 struct __is_destructible_impl_1
569 : public __do_is_destructible_impl_1
571 typedef decltype(__test<_Tp>(0)) type;
574 struct __do_is_destructible_impl_2
576 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
577 static true_type __test(int);
580 static false_type __test(...);
583 template<typename _Tp>
584 struct __is_destructible_impl_2
585 : public __do_is_destructible_impl_2
587 typedef decltype(__test<_Tp>(0)) type;
590 template<typename _Tp,
591 bool = __or_<is_void<_Tp>,
592 __is_array_unknown_bounds<_Tp>>::value,
593 bool = __or_<is_reference<_Tp>, is_function<_Tp>>::value>
594 struct __is_destructible_safe;
596 template<typename _Tp>
597 struct __is_destructible_safe<_Tp, false, false>
598 : public conditional<is_abstract<_Tp>::value,
599 __is_destructible_impl_2<_Tp>,
600 __is_destructible_impl_1<_Tp>>::type::type
603 template<typename _Tp>
604 struct __is_destructible_safe<_Tp, true, false>
605 : public false_type { };
607 template<typename _Tp>
608 struct __is_destructible_safe<_Tp, false, true>
609 : public true_type { };
612 template<typename _Tp>
613 struct is_destructible
614 : public integral_constant<bool, (__is_destructible_safe<_Tp>::value)>
617 struct __do_is_default_constructible_impl
619 template<typename _Tp, typename = decltype(_Tp())>
620 static true_type __test(int);
623 static false_type __test(...);
626 template<typename _Tp>
627 struct __is_default_constructible_impl
628 : public __do_is_default_constructible_impl
630 typedef decltype(__test<_Tp>(0)) type;
633 template<typename _Tp>
634 struct __is_default_constructible_atom
635 : public __and_<is_destructible<_Tp>,
636 __is_default_constructible_impl<_Tp>>::type::type
639 template<typename _Tp, bool = is_array<_Tp>::value>
640 struct __is_default_constructible_safe;
642 // The following technique is a workaround for a gcc defect, which does
643 // not sfinae away attempts to default-construct arrays of unknown bounds.
644 // Complete arrays can be default-constructed, if the element type is
645 // default-constructible, but arrays with unknown bounds are not:
647 template<typename _Tp>
648 struct __is_default_constructible_safe<_Tp, true>
649 : public __and_<__is_array_known_bounds<_Tp>,
650 __is_default_constructible_atom<typename
651 remove_all_extents<_Tp>::type>>::type::type
654 template<typename _Tp>
655 struct __is_default_constructible_safe<_Tp, false>
656 : public __is_default_constructible_atom<_Tp>::type
659 /// is_default_constructible
660 template<typename _Tp>
661 struct is_default_constructible
662 : public integral_constant<bool, (__is_default_constructible_safe<
666 struct __do_is_static_castable_impl
668 template<typename _From, typename _To, typename
669 = decltype(static_cast<_To>(declval<_From>()))>
670 static true_type __test(int);
672 template<typename, typename>
673 static false_type __test(...);
676 template<typename _From, typename _To>
677 struct __is_static_castable_impl
678 : public __do_is_static_castable_impl
680 typedef decltype(__test<_From, _To>(0)) type;
683 template<typename _From, typename _To>
684 struct __is_static_castable_safe
685 : public __and_<__or_<is_void<_To>, is_destructible<_To>>,
686 __is_static_castable_impl<_From, _To>>::type::type
689 // __is_static_castable
690 template<typename _From, typename _To>
691 struct __is_static_castable
692 : public integral_constant<bool, (__is_static_castable_safe<
696 struct __do_is_direct_constructible_impl
698 template<typename _Tp, typename _Arg, typename
699 = decltype(::new _Tp(declval<_Arg>()))>
700 static true_type __test(int);
702 template<typename, typename>
703 static false_type __test(...);
706 template<typename _Tp, typename _Arg>
707 struct __is_direct_constructible_impl
708 : public __do_is_direct_constructible_impl
710 typedef decltype(__test<_Tp, _Arg>(0)) type;
713 template<typename _Tp, typename _Arg>
714 struct __is_direct_constructible_new_safe
715 : public __and_<is_destructible<_Tp>,
716 __is_direct_constructible_impl<_Tp, _Arg>>::type::type
719 template<typename, typename>
722 template<typename, typename>
726 struct remove_reference;
728 template<typename _From, typename _To, bool
729 = is_reference<_From>::value>
730 struct __is_base_to_derived_ref;
732 template<typename _From, typename _To>
733 struct __is_base_to_derived_ref<_From, _To, true>
735 typedef typename remove_cv<typename remove_reference<_From
736 >::type>::type __src_t;
737 typedef typename remove_cv<typename remove_reference<_To
738 >::type>::type __dst_t;
739 typedef typename __and_<
740 __not_<is_same<__src_t, __dst_t>>,
741 is_base_of<__src_t, __dst_t>
743 static constexpr bool value = type::value;
746 template<typename _From, typename _To>
747 struct __is_base_to_derived_ref<_From, _To, false>
751 template<typename _From, typename _To, bool
752 = __and_<is_lvalue_reference<_From>,
753 is_rvalue_reference<_To>>::value>
754 struct __is_lvalue_to_rvalue_ref;
756 template<typename _From, typename _To>
757 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
759 typedef typename remove_cv<typename remove_reference<
760 _From>::type>::type __src_t;
761 typedef typename remove_cv<typename remove_reference<
762 _To>::type>::type __dst_t;
763 typedef typename __or_<
764 is_same<__src_t, __dst_t>,
765 is_base_of<__dst_t, __src_t>
767 static constexpr bool value = type::value;
770 template<typename _From, typename _To>
771 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
775 // Here we handle direct-initialization to a reference type
776 // as equivalent to a static_cast modulo overshooting conversions.
777 // These are restricted to the following conversion:
778 // a) A base class to a derived class reference
779 // b) An lvalue-reference to an rvalue-reference
781 template<typename _Tp, typename _Arg>
782 struct __is_direct_constructible_ref_cast
783 : public __and_<__is_static_castable<_Arg, _Tp>,
784 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
785 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
789 // Direct-initialization is tricky, because of functional
790 // casts: For a conversion to reference we fall back to a
791 // static_cast modulo extra cases, otherwise we use a
794 template<typename _Tp, typename _Arg>
795 struct __is_direct_constructible_new
796 : public conditional<is_reference<_Tp>::value,
797 __is_direct_constructible_ref_cast<_Tp, _Arg>,
798 __is_direct_constructible_new_safe<_Tp, _Arg>
802 template<typename _Tp, typename _Arg>
803 struct __is_direct_constructible
804 : public integral_constant<bool, (__is_direct_constructible_new<
805 _Tp, _Arg>::type::value)>
808 struct __do_is_nary_constructible_impl
810 template<typename _Tp, typename... _Args, typename
811 = decltype(_Tp(declval<_Args>()...))>
812 static true_type __test(int);
814 template<typename, typename...>
815 static false_type __test(...);
818 template<typename _Tp, typename... _Args>
819 struct __is_nary_constructible_impl
820 : public __do_is_nary_constructible_impl
822 typedef decltype(__test<_Tp, _Args...>(0)) type;
825 template<typename _Tp, typename... _Args>
826 struct __is_nary_constructible
827 : public __and_<is_destructible<_Tp>,
828 __is_nary_constructible_impl<_Tp, _Args...>
831 static_assert(sizeof...(_Args) > 1,
832 "Only useful for > 1 arguments");
835 template<typename _Tp, typename... _Args>
836 struct __is_constructible_impl
837 : public __is_nary_constructible<_Tp, _Args...>
840 template<typename _Tp, typename _Arg>
841 struct __is_constructible_impl<_Tp, _Arg>
842 : public __is_direct_constructible<_Tp, _Arg>
845 template<typename _Tp>
846 struct __is_constructible_impl<_Tp>
847 : public is_default_constructible<_Tp>
851 template<typename _Tp, typename... _Args>
852 struct is_constructible
853 : public integral_constant<bool, (__is_constructible_impl<_Tp,
858 template<bool, typename _Tp, typename... _Args>
859 struct __is_nt_constructible_helper
860 { static const bool __value = false; };
862 template<typename _Tp, typename... _Args>
863 struct __is_nt_constructible_helper<true, _Tp, _Args...>
864 { static const bool __value = noexcept(_Tp(declval<_Args>()...)); };
866 template<typename _Tp, typename _Arg>
867 struct __is_nt_constructible_helper<true, _Tp, _Arg>
869 static const bool __value = noexcept(static_cast<_Tp>(declval<_Arg>()));
872 /// is_nothrow_constructible
873 template<typename _Tp, typename... _Args>
874 struct is_nothrow_constructible
875 : public integral_constant<bool,
876 __is_nt_constructible_helper<is_constructible<_Tp, _Args...>::value,
877 _Tp, _Args...>::__value>
880 /// has_trivial_default_constructor
881 template<typename _Tp>
882 struct has_trivial_default_constructor
883 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
886 /// has_trivial_copy_constructor
887 template<typename _Tp>
888 struct has_trivial_copy_constructor
889 : public integral_constant<bool, __has_trivial_copy(_Tp)>
892 /// has_trivial_copy_assign
893 template<typename _Tp>
894 struct has_trivial_copy_assign
895 : public integral_constant<bool, __has_trivial_assign(_Tp)>
898 /// has_trivial_destructor
899 template<typename _Tp>
900 struct has_trivial_destructor
901 : public integral_constant<bool, __has_trivial_destructor(_Tp)>
904 /// has_nothrow_default_constructor
905 template<typename _Tp>
906 struct has_nothrow_default_constructor
907 : public integral_constant<bool, __has_nothrow_constructor(_Tp)>
910 /// has_nothrow_copy_constructor
911 template<typename _Tp>
912 struct has_nothrow_copy_constructor
913 : public integral_constant<bool, __has_nothrow_copy(_Tp)>
916 /// has_nothrow_copy_assign
917 template<typename _Tp>
918 struct has_nothrow_copy_assign
919 : public integral_constant<bool, __has_nothrow_assign(_Tp)>
922 /// has_virtual_destructor
923 template<typename _Tp>
924 struct has_virtual_destructor
925 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
929 // type property queries.
932 template<typename _Tp>
934 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
939 : public integral_constant<std::size_t, 0> { };
941 template<typename _Tp, std::size_t _Size>
942 struct rank<_Tp[_Size]>
943 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
945 template<typename _Tp>
947 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
950 template<typename, unsigned _Uint>
952 : public integral_constant<std::size_t, 0> { };
954 template<typename _Tp, unsigned _Uint, std::size_t _Size>
955 struct extent<_Tp[_Size], _Uint>
956 : public integral_constant<std::size_t,
957 _Uint == 0 ? _Size : extent<_Tp,
961 template<typename _Tp, unsigned _Uint>
962 struct extent<_Tp[], _Uint>
963 : public integral_constant<std::size_t,
964 _Uint == 0 ? 0 : extent<_Tp,
972 template<typename, typename>
974 : public false_type { };
976 template<typename _Tp>
977 struct is_same<_Tp, _Tp>
978 : public true_type { };
981 template<typename _Base, typename _Derived>
983 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
986 template<typename _From, typename _To,
987 bool = __or_<is_void<_From>, is_function<_To>,
988 is_array<_To>>::value>
989 struct __is_convertible_helper
990 { static const bool __value = is_void<_To>::value; };
992 template<typename _From, typename _To>
993 class __is_convertible_helper<_From, _To, false>
994 : public __sfinae_types
996 template<typename _To1>
997 static void __test_aux(_To1);
999 template<typename _From1, typename _To1>
1000 static decltype(__test_aux<_To1>(std::declval<_From1>()), __one())
1003 template<typename, typename>
1004 static __two __test(...);
1007 static const bool __value = sizeof(__test<_From, _To>(0)) == 1;
1011 template<typename _From, typename _To>
1012 struct is_convertible
1013 : public integral_constant<bool,
1014 __is_convertible_helper<_From, _To>::__value>
1017 /// is_explicitly_convertible
1018 template<typename _From, typename _To>
1019 struct is_explicitly_convertible
1020 : public is_constructible<_To, _From>
1024 // const-volatile modifications.
1027 template<typename _Tp>
1029 { typedef _Tp type; };
1031 template<typename _Tp>
1032 struct remove_const<_Tp const>
1033 { typedef _Tp type; };
1036 template<typename _Tp>
1037 struct remove_volatile
1038 { typedef _Tp type; };
1040 template<typename _Tp>
1041 struct remove_volatile<_Tp volatile>
1042 { typedef _Tp type; };
1045 template<typename _Tp>
1049 remove_const<typename remove_volatile<_Tp>::type>::type type;
1053 template<typename _Tp>
1055 { typedef _Tp const type; };
1058 template<typename _Tp>
1060 { typedef _Tp volatile type; };
1063 template<typename _Tp>
1067 add_const<typename add_volatile<_Tp>::type>::type type;
1071 // Reference transformations.
1073 /// remove_reference
1074 template<typename _Tp>
1075 struct remove_reference
1076 { typedef _Tp type; };
1078 template<typename _Tp>
1079 struct remove_reference<_Tp&>
1080 { typedef _Tp type; };
1082 template<typename _Tp>
1083 struct remove_reference<_Tp&&>
1084 { typedef _Tp type; };
1086 template<typename _Tp,
1087 bool = __and_<__not_<is_reference<_Tp>>,
1088 __not_<is_void<_Tp>>>::value,
1089 bool = is_rvalue_reference<_Tp>::value>
1090 struct __add_lvalue_reference_helper
1091 { typedef _Tp type; };
1093 template<typename _Tp>
1094 struct __add_lvalue_reference_helper<_Tp, true, false>
1095 { typedef _Tp& type; };
1097 template<typename _Tp>
1098 struct __add_lvalue_reference_helper<_Tp, false, true>
1099 { typedef typename remove_reference<_Tp>::type& type; };
1101 /// add_lvalue_reference
1102 template<typename _Tp>
1103 struct add_lvalue_reference
1104 : public __add_lvalue_reference_helper<_Tp>
1107 template<typename _Tp,
1108 bool = __and_<__not_<is_reference<_Tp>>,
1109 __not_<is_void<_Tp>>>::value>
1110 struct __add_rvalue_reference_helper
1111 { typedef _Tp type; };
1113 template<typename _Tp>
1114 struct __add_rvalue_reference_helper<_Tp, true>
1115 { typedef _Tp&& type; };
1117 /// add_rvalue_reference
1118 template<typename _Tp>
1119 struct add_rvalue_reference
1120 : public __add_rvalue_reference_helper<_Tp>
1124 // sign modifications.
1126 // Utility for constructing identically cv-qualified types.
1127 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1128 struct __cv_selector;
1130 template<typename _Unqualified>
1131 struct __cv_selector<_Unqualified, false, false>
1132 { typedef _Unqualified __type; };
1134 template<typename _Unqualified>
1135 struct __cv_selector<_Unqualified, false, true>
1136 { typedef volatile _Unqualified __type; };
1138 template<typename _Unqualified>
1139 struct __cv_selector<_Unqualified, true, false>
1140 { typedef const _Unqualified __type; };
1142 template<typename _Unqualified>
1143 struct __cv_selector<_Unqualified, true, true>
1144 { typedef const volatile _Unqualified __type; };
1146 template<typename _Qualified, typename _Unqualified,
1147 bool _IsConst = is_const<_Qualified>::value,
1148 bool _IsVol = is_volatile<_Qualified>::value>
1149 class __match_cv_qualifiers
1151 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1154 typedef typename __match::__type __type;
1157 // Utility for finding the unsigned versions of signed integral types.
1158 template<typename _Tp>
1159 struct __make_unsigned
1160 { typedef _Tp __type; };
1163 struct __make_unsigned<char>
1164 { typedef unsigned char __type; };
1167 struct __make_unsigned<signed char>
1168 { typedef unsigned char __type; };
1171 struct __make_unsigned<short>
1172 { typedef unsigned short __type; };
1175 struct __make_unsigned<int>
1176 { typedef unsigned int __type; };
1179 struct __make_unsigned<long>
1180 { typedef unsigned long __type; };
1183 struct __make_unsigned<long long>
1184 { typedef unsigned long long __type; };
1186 // Select between integral and enum: not possible to be both.
1187 template<typename _Tp,
1188 bool _IsInt = is_integral<_Tp>::value,
1189 bool _IsEnum = is_enum<_Tp>::value>
1190 class __make_unsigned_selector;
1192 template<typename _Tp>
1193 class __make_unsigned_selector<_Tp, true, false>
1195 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1196 typedef typename __unsignedt::__type __unsigned_type;
1197 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1200 typedef typename __cv_unsigned::__type __type;
1203 template<typename _Tp>
1204 class __make_unsigned_selector<_Tp, false, true>
1206 // With -fshort-enums, an enum may be as small as a char.
1207 typedef unsigned char __smallest;
1208 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1209 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1210 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1211 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1212 typedef typename __cond2::type __cond2_type;
1213 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1214 typedef typename __cond1::type __cond1_type;
1217 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1220 // Given an integral/enum type, return the corresponding unsigned
1222 // Primary template.
1224 template<typename _Tp>
1225 struct make_unsigned
1226 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1228 // Integral, but don't define.
1230 struct make_unsigned<bool>;
1233 // Utility for finding the signed versions of unsigned integral types.
1234 template<typename _Tp>
1235 struct __make_signed
1236 { typedef _Tp __type; };
1239 struct __make_signed<char>
1240 { typedef signed char __type; };
1243 struct __make_signed<unsigned char>
1244 { typedef signed char __type; };
1247 struct __make_signed<unsigned short>
1248 { typedef signed short __type; };
1251 struct __make_signed<unsigned int>
1252 { typedef signed int __type; };
1255 struct __make_signed<unsigned long>
1256 { typedef signed long __type; };
1259 struct __make_signed<unsigned long long>
1260 { typedef signed long long __type; };
1262 // Select between integral and enum: not possible to be both.
1263 template<typename _Tp,
1264 bool _IsInt = is_integral<_Tp>::value,
1265 bool _IsEnum = is_enum<_Tp>::value>
1266 class __make_signed_selector;
1268 template<typename _Tp>
1269 class __make_signed_selector<_Tp, true, false>
1271 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1272 typedef typename __signedt::__type __signed_type;
1273 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1276 typedef typename __cv_signed::__type __type;
1279 template<typename _Tp>
1280 class __make_signed_selector<_Tp, false, true>
1282 // With -fshort-enums, an enum may be as small as a char.
1283 typedef signed char __smallest;
1284 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1285 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1286 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1287 typedef conditional<__b2, signed int, signed long> __cond2;
1288 typedef typename __cond2::type __cond2_type;
1289 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1290 typedef typename __cond1::type __cond1_type;
1293 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1296 // Given an integral/enum type, return the corresponding signed
1298 // Primary template.
1300 template<typename _Tp>
1302 { typedef typename __make_signed_selector<_Tp>::__type type; };
1304 // Integral, but don't define.
1306 struct make_signed<bool>;
1309 // array modifications.
1312 template<typename _Tp>
1313 struct remove_extent
1314 { typedef _Tp type; };
1316 template<typename _Tp, std::size_t _Size>
1317 struct remove_extent<_Tp[_Size]>
1318 { typedef _Tp type; };
1320 template<typename _Tp>
1321 struct remove_extent<_Tp[]>
1322 { typedef _Tp type; };
1324 /// remove_all_extents
1325 template<typename _Tp>
1326 struct remove_all_extents
1327 { typedef _Tp type; };
1329 template<typename _Tp, std::size_t _Size>
1330 struct remove_all_extents<_Tp[_Size]>
1331 { typedef typename remove_all_extents<_Tp>::type type; };
1333 template<typename _Tp>
1334 struct remove_all_extents<_Tp[]>
1335 { typedef typename remove_all_extents<_Tp>::type type; };
1338 // pointer modifications.
1340 template<typename _Tp, typename>
1341 struct __remove_pointer_helper
1342 { typedef _Tp type; };
1344 template<typename _Tp, typename _Up>
1345 struct __remove_pointer_helper<_Tp, _Up*>
1346 { typedef _Up type; };
1349 template<typename _Tp>
1350 struct remove_pointer
1351 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1355 template<typename _Tp>
1357 { typedef typename remove_reference<_Tp>::type* type; };
1360 template<std::size_t _Len>
1361 struct __aligned_storage_msa
1365 unsigned char __data[_Len];
1366 struct __attribute__((__aligned__)) { } __align;
1371 * @brief Alignment type.
1373 * The value of _Align is a default-alignment which shall be the
1374 * most stringent alignment requirement for any C++ object type
1375 * whose size is no greater than _Len (3.9). The member typedef
1376 * type shall be a POD type suitable for use as uninitialized
1377 * storage for any object whose size is at most _Len and whose
1378 * alignment is a divisor of _Align.
1380 template<std::size_t _Len, std::size_t _Align =
1381 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1382 struct aligned_storage
1386 unsigned char __data[_Len];
1387 struct __attribute__((__aligned__((_Align)))) { } __align;
1392 // Decay trait for arrays and functions, used for perfect forwarding
1393 // in make_pair, make_tuple, etc.
1394 template<typename _Up,
1395 bool _IsArray = is_array<_Up>::value,
1396 bool _IsFunction = is_function<_Up>::value>
1397 struct __decay_selector;
1400 template<typename _Up>
1401 struct __decay_selector<_Up, false, false>
1402 { typedef typename remove_cv<_Up>::type __type; };
1404 template<typename _Up>
1405 struct __decay_selector<_Up, true, false>
1406 { typedef typename remove_extent<_Up>::type* __type; };
1408 template<typename _Up>
1409 struct __decay_selector<_Up, false, true>
1410 { typedef typename add_pointer<_Up>::type __type; };
1413 template<typename _Tp>
1416 typedef typename remove_reference<_Tp>::type __remove_type;
1419 typedef typename __decay_selector<__remove_type>::__type type;
1422 template<typename _Tp>
1423 class reference_wrapper;
1425 // Helper which adds a reference to a type when given a reference_wrapper
1426 template<typename _Tp>
1427 struct __strip_reference_wrapper
1432 template<typename _Tp>
1433 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1435 typedef _Tp& __type;
1438 template<typename _Tp>
1439 struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
1441 typedef _Tp& __type;
1444 template<typename _Tp>
1445 struct __decay_and_strip
1447 typedef typename __strip_reference_wrapper<
1448 typename decay<_Tp>::type>::__type __type;
1452 // Define a nested type if some predicate holds.
1453 // Primary template.
1455 template<bool, typename _Tp = void>
1459 // Partial specialization for true.
1460 template<typename _Tp>
1461 struct enable_if<true, _Tp>
1462 { typedef _Tp type; };
1465 // A conditional expression, but for types. If true, first, if false, second.
1466 // Primary template.
1468 template<bool _Cond, typename _Iftrue, typename _Iffalse>
1470 { typedef _Iftrue type; };
1472 // Partial specialization for false.
1473 template<typename _Iftrue, typename _Iffalse>
1474 struct conditional<false, _Iftrue, _Iffalse>
1475 { typedef _Iffalse type; };
1479 template<typename... _Tp>
1482 template<typename _Tp>
1483 struct common_type<_Tp>
1484 { typedef _Tp type; };
1486 template<typename _Tp, typename _Up>
1487 struct common_type<_Tp, _Up>
1488 { typedef decltype(true ? declval<_Tp>() : declval<_Up>()) type; };
1490 template<typename _Tp, typename _Up, typename... _Vp>
1491 struct common_type<_Tp, _Up, _Vp...>
1494 common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
1497 /// underlying_type (still unimplemented)
1500 template<typename _Signature>
1503 template<typename _Functor, typename... _ArgTypes>
1504 struct result_of<_Functor(_ArgTypes...)>
1507 decltype( std::declval<_Functor>()(std::declval<_ArgTypes>()...) )
1512 template<typename _Tp>
1513 struct __declval_protector
1515 static const bool __stop = false;
1516 static typename add_rvalue_reference<_Tp>::type __delegate();
1519 template<typename _Tp>
1520 inline typename add_rvalue_reference<_Tp>::type
1523 static_assert(__declval_protector<_Tp>::__stop,
1524 "declval() must not be used!");
1525 return __declval_protector<_Tp>::__delegate();
1529 * Use SFINAE to determine if the type _Tp has a publicly-accessible
1530 * member type _NTYPE.
1532 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
1533 template<typename _Tp> \
1534 class __has_##_NTYPE##_helper \
1537 template<typename _Up> \
1541 template<typename _Up> \
1542 static __one __test(_Wrap_type<typename _Up::_NTYPE>*); \
1544 template<typename _Up> \
1545 static __two __test(...); \
1548 static const bool value = sizeof(__test<_Tp>(0)) == 1; \
1551 template<typename _Tp> \
1552 struct __has_##_NTYPE \
1553 : integral_constant<bool, __has_##_NTYPE##_helper \
1554 <typename remove_cv<_Tp>::type>::value> \
1557 // @} group metaprogramming
1558 _GLIBCXX_END_NAMESPACE_VERSION
1561 #endif // __GXX_EXPERIMENTAL_CXX0X__
1563 #endif // _GLIBCXX_TYPE_TRAITS