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
77 #define __cpp_lib_integral_constant_callable 201304
79 constexpr value_type operator()() const { return value; }
83 template<typename _Tp, _Tp __v>
84 constexpr _Tp integral_constant<_Tp, __v>::value;
86 /// The type used as a compile-time boolean with true value.
87 typedef integral_constant<bool, true> true_type;
89 /// The type used as a compile-time boolean with false value.
90 typedef integral_constant<bool, false> false_type;
92 // Meta programming helper types.
94 template<bool, typename, typename>
105 template<typename _B1>
110 template<typename _B1, typename _B2>
111 struct __or_<_B1, _B2>
112 : public conditional<_B1::value, _B1, _B2>::type
115 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
116 struct __or_<_B1, _B2, _B3, _Bn...>
117 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
120 template<typename...>
128 template<typename _B1>
133 template<typename _B1, typename _B2>
134 struct __and_<_B1, _B2>
135 : public conditional<_B1::value, _B2, _B1>::type
138 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
139 struct __and_<_B1, _B2, _B3, _Bn...>
140 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
143 template<typename _Pp>
145 : public integral_constant<bool, !_Pp::value>
148 // For several sfinae-friendly trait implementations we transport both the
149 // result information (as the member type) and the failure information (no
150 // member type). This is very similar to std::enable_if, but we cannot use
151 // them, because we need to derive from them as an implementation detail.
153 template<typename _Tp>
154 struct __success_type
155 { typedef _Tp type; };
157 struct __failure_type
160 // Primary type categories.
166 struct __is_void_helper
167 : public false_type { };
170 struct __is_void_helper<void>
171 : public true_type { };
174 template<typename _Tp>
176 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
180 struct __is_integral_helper
181 : public false_type { };
184 struct __is_integral_helper<bool>
185 : public true_type { };
188 struct __is_integral_helper<char>
189 : public true_type { };
192 struct __is_integral_helper<signed char>
193 : public true_type { };
196 struct __is_integral_helper<unsigned char>
197 : public true_type { };
199 #ifdef _GLIBCXX_USE_WCHAR_T
201 struct __is_integral_helper<wchar_t>
202 : public true_type { };
206 struct __is_integral_helper<char16_t>
207 : public true_type { };
210 struct __is_integral_helper<char32_t>
211 : public true_type { };
214 struct __is_integral_helper<short>
215 : public true_type { };
218 struct __is_integral_helper<unsigned short>
219 : public true_type { };
222 struct __is_integral_helper<int>
223 : public true_type { };
226 struct __is_integral_helper<unsigned int>
227 : public true_type { };
230 struct __is_integral_helper<long>
231 : public true_type { };
234 struct __is_integral_helper<unsigned long>
235 : public true_type { };
238 struct __is_integral_helper<long long>
239 : public true_type { };
242 struct __is_integral_helper<unsigned long long>
243 : public true_type { };
245 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
247 struct __is_integral_helper<__int128>
248 : public true_type { };
251 struct __is_integral_helper<unsigned __int128>
252 : public true_type { };
256 template<typename _Tp>
258 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
262 struct __is_floating_point_helper
263 : public false_type { };
266 struct __is_floating_point_helper<float>
267 : public true_type { };
270 struct __is_floating_point_helper<double>
271 : public true_type { };
274 struct __is_floating_point_helper<long double>
275 : public true_type { };
277 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
279 struct __is_floating_point_helper<__float128>
280 : public true_type { };
283 /// is_floating_point
284 template<typename _Tp>
285 struct is_floating_point
286 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
292 : public false_type { };
294 template<typename _Tp, std::size_t _Size>
295 struct is_array<_Tp[_Size]>
296 : public true_type { };
298 template<typename _Tp>
299 struct is_array<_Tp[]>
300 : public true_type { };
303 struct __is_pointer_helper
304 : public false_type { };
306 template<typename _Tp>
307 struct __is_pointer_helper<_Tp*>
308 : public true_type { };
311 template<typename _Tp>
313 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
316 /// is_lvalue_reference
318 struct is_lvalue_reference
319 : public false_type { };
321 template<typename _Tp>
322 struct is_lvalue_reference<_Tp&>
323 : public true_type { };
325 /// is_rvalue_reference
327 struct is_rvalue_reference
328 : public false_type { };
330 template<typename _Tp>
331 struct is_rvalue_reference<_Tp&&>
332 : public true_type { };
338 struct __is_member_object_pointer_helper
339 : public false_type { };
341 template<typename _Tp, typename _Cp>
342 struct __is_member_object_pointer_helper<_Tp _Cp::*>
343 : public integral_constant<bool, !is_function<_Tp>::value> { };
345 /// is_member_object_pointer
346 template<typename _Tp>
347 struct is_member_object_pointer
348 : public __is_member_object_pointer_helper<
349 typename remove_cv<_Tp>::type>::type
353 struct __is_member_function_pointer_helper
354 : public false_type { };
356 template<typename _Tp, typename _Cp>
357 struct __is_member_function_pointer_helper<_Tp _Cp::*>
358 : public integral_constant<bool, is_function<_Tp>::value> { };
360 /// is_member_function_pointer
361 template<typename _Tp>
362 struct is_member_function_pointer
363 : public __is_member_function_pointer_helper<
364 typename remove_cv<_Tp>::type>::type
368 template<typename _Tp>
370 : public integral_constant<bool, __is_enum(_Tp)>
374 template<typename _Tp>
376 : public integral_constant<bool, __is_union(_Tp)>
380 template<typename _Tp>
382 : public integral_constant<bool, __is_class(_Tp)>
388 : public false_type { };
390 template<typename _Res, typename... _ArgTypes>
391 struct is_function<_Res(_ArgTypes...)>
392 : public true_type { };
394 template<typename _Res, typename... _ArgTypes>
395 struct is_function<_Res(_ArgTypes...) &>
396 : public true_type { };
398 template<typename _Res, typename... _ArgTypes>
399 struct is_function<_Res(_ArgTypes...) &&>
400 : public true_type { };
402 template<typename _Res, typename... _ArgTypes>
403 struct is_function<_Res(_ArgTypes......)>
404 : public true_type { };
406 template<typename _Res, typename... _ArgTypes>
407 struct is_function<_Res(_ArgTypes......) &>
408 : public true_type { };
410 template<typename _Res, typename... _ArgTypes>
411 struct is_function<_Res(_ArgTypes......) &&>
412 : public true_type { };
414 template<typename _Res, typename... _ArgTypes>
415 struct is_function<_Res(_ArgTypes...) const>
416 : public true_type { };
418 template<typename _Res, typename... _ArgTypes>
419 struct is_function<_Res(_ArgTypes...) const &>
420 : public true_type { };
422 template<typename _Res, typename... _ArgTypes>
423 struct is_function<_Res(_ArgTypes...) const &&>
424 : public true_type { };
426 template<typename _Res, typename... _ArgTypes>
427 struct is_function<_Res(_ArgTypes......) const>
428 : public true_type { };
430 template<typename _Res, typename... _ArgTypes>
431 struct is_function<_Res(_ArgTypes......) const &>
432 : public true_type { };
434 template<typename _Res, typename... _ArgTypes>
435 struct is_function<_Res(_ArgTypes......) const &&>
436 : public true_type { };
438 template<typename _Res, typename... _ArgTypes>
439 struct is_function<_Res(_ArgTypes...) volatile>
440 : public true_type { };
442 template<typename _Res, typename... _ArgTypes>
443 struct is_function<_Res(_ArgTypes...) volatile &>
444 : public true_type { };
446 template<typename _Res, typename... _ArgTypes>
447 struct is_function<_Res(_ArgTypes...) volatile &&>
448 : public true_type { };
450 template<typename _Res, typename... _ArgTypes>
451 struct is_function<_Res(_ArgTypes......) volatile>
452 : public true_type { };
454 template<typename _Res, typename... _ArgTypes>
455 struct is_function<_Res(_ArgTypes......) volatile &>
456 : public true_type { };
458 template<typename _Res, typename... _ArgTypes>
459 struct is_function<_Res(_ArgTypes......) volatile &&>
460 : public true_type { };
462 template<typename _Res, typename... _ArgTypes>
463 struct is_function<_Res(_ArgTypes...) const volatile>
464 : public true_type { };
466 template<typename _Res, typename... _ArgTypes>
467 struct is_function<_Res(_ArgTypes...) const volatile &>
468 : public true_type { };
470 template<typename _Res, typename... _ArgTypes>
471 struct is_function<_Res(_ArgTypes...) const volatile &&>
472 : public true_type { };
474 template<typename _Res, typename... _ArgTypes>
475 struct is_function<_Res(_ArgTypes......) const volatile>
476 : public true_type { };
478 template<typename _Res, typename... _ArgTypes>
479 struct is_function<_Res(_ArgTypes......) const volatile &>
480 : public true_type { };
482 template<typename _Res, typename... _ArgTypes>
483 struct is_function<_Res(_ArgTypes......) const volatile &&>
484 : public true_type { };
486 #define __cpp_lib_is_null_pointer 201309
489 struct __is_null_pointer_helper
490 : public false_type { };
493 struct __is_null_pointer_helper<std::nullptr_t>
494 : public true_type { };
496 /// is_null_pointer (LWG 2247).
497 template<typename _Tp>
498 struct is_null_pointer
499 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
502 /// __is_nullptr_t (extension).
503 template<typename _Tp>
504 struct __is_nullptr_t
505 : public is_null_pointer<_Tp>
508 // Composite type categories.
511 template<typename _Tp>
513 : public __or_<is_lvalue_reference<_Tp>,
514 is_rvalue_reference<_Tp>>::type
518 template<typename _Tp>
520 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
524 template<typename _Tp>
525 struct is_fundamental
526 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
527 is_null_pointer<_Tp>>::type
531 template<typename _Tp>
533 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
538 struct is_member_pointer;
541 template<typename _Tp>
543 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
544 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
548 template<typename _Tp>
550 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
552 template<typename _Tp>
553 struct __is_member_pointer_helper
554 : public false_type { };
556 template<typename _Tp, typename _Cp>
557 struct __is_member_pointer_helper<_Tp _Cp::*>
558 : public true_type { };
560 /// is_member_pointer
561 template<typename _Tp>
562 struct is_member_pointer
563 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
566 // Utility to detect referenceable types ([defns.referenceable]).
568 template<typename _Tp>
569 struct __is_referenceable
570 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
573 template<typename _Res, typename... _Args>
574 struct __is_referenceable<_Res(_Args...)>
578 template<typename _Res, typename... _Args>
579 struct __is_referenceable<_Res(_Args......)>
588 : public false_type { };
590 template<typename _Tp>
591 struct is_const<_Tp const>
592 : public true_type { };
597 : public false_type { };
599 template<typename _Tp>
600 struct is_volatile<_Tp volatile>
601 : public true_type { };
604 template<typename _Tp>
606 : public integral_constant<bool, __is_trivial(_Tp)>
609 // is_trivially_copyable (still unimplemented)
611 /// is_standard_layout
612 template<typename _Tp>
613 struct is_standard_layout
614 : public integral_constant<bool, __is_standard_layout(_Tp)>
618 // Could use is_standard_layout && is_trivial instead of the builtin.
619 template<typename _Tp>
621 : public integral_constant<bool, __is_pod(_Tp)>
625 template<typename _Tp>
626 struct is_literal_type
627 : public integral_constant<bool, __is_literal_type(_Tp)>
631 template<typename _Tp>
633 : public integral_constant<bool, __is_empty(_Tp)>
637 template<typename _Tp>
638 struct is_polymorphic
639 : public integral_constant<bool, __is_polymorphic(_Tp)>
642 #if __cplusplus > 201103L
644 #define __cpp_lib_is_final 201402L
645 template<typename _Tp>
647 : public integral_constant<bool, __is_final(_Tp)>
652 template<typename _Tp>
654 : public integral_constant<bool, __is_abstract(_Tp)>
657 template<typename _Tp,
658 bool = is_arithmetic<_Tp>::value>
659 struct __is_signed_helper
660 : public false_type { };
662 template<typename _Tp>
663 struct __is_signed_helper<_Tp, true>
664 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
668 template<typename _Tp>
670 : public __is_signed_helper<_Tp>::type
674 template<typename _Tp>
676 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
680 // Destructible and constructible type properties.
683 struct add_rvalue_reference;
686 * @brief Utility to simplify expressions used in unevaluated operands
689 template<typename _Tp>
690 typename add_rvalue_reference<_Tp>::type declval() noexcept;
692 template<typename, unsigned = 0>
696 struct remove_all_extents;
698 template<typename _Tp>
699 struct __is_array_known_bounds
700 : public integral_constant<bool, (extent<_Tp>::value > 0)>
703 template<typename _Tp>
704 struct __is_array_unknown_bounds
705 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
708 // In N3290 is_destructible does not say anything about function
709 // types and abstract types, see LWG 2049. This implementation
710 // describes function types as non-destructible and all complete
711 // object types as destructible, iff the explicit destructor
712 // call expression is wellformed.
713 struct __do_is_destructible_impl
715 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
716 static true_type __test(int);
719 static false_type __test(...);
722 template<typename _Tp>
723 struct __is_destructible_impl
724 : public __do_is_destructible_impl
726 typedef decltype(__test<_Tp>(0)) type;
729 template<typename _Tp,
730 bool = __or_<is_void<_Tp>,
731 __is_array_unknown_bounds<_Tp>,
732 is_function<_Tp>>::value,
733 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
734 struct __is_destructible_safe;
736 template<typename _Tp>
737 struct __is_destructible_safe<_Tp, false, false>
738 : public __is_destructible_impl<typename
739 remove_all_extents<_Tp>::type>::type
742 template<typename _Tp>
743 struct __is_destructible_safe<_Tp, true, false>
744 : public false_type { };
746 template<typename _Tp>
747 struct __is_destructible_safe<_Tp, false, true>
748 : public true_type { };
751 template<typename _Tp>
752 struct is_destructible
753 : public __is_destructible_safe<_Tp>::type
756 // is_nothrow_destructible requires that is_destructible is
757 // satisfied as well. We realize that by mimicing the
758 // implementation of is_destructible but refer to noexcept(expr)
759 // instead of decltype(expr).
760 struct __do_is_nt_destructible_impl
762 template<typename _Tp>
763 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
767 static false_type __test(...);
770 template<typename _Tp>
771 struct __is_nt_destructible_impl
772 : public __do_is_nt_destructible_impl
774 typedef decltype(__test<_Tp>(0)) type;
777 template<typename _Tp,
778 bool = __or_<is_void<_Tp>,
779 __is_array_unknown_bounds<_Tp>,
780 is_function<_Tp>>::value,
781 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
782 struct __is_nt_destructible_safe;
784 template<typename _Tp>
785 struct __is_nt_destructible_safe<_Tp, false, false>
786 : public __is_nt_destructible_impl<typename
787 remove_all_extents<_Tp>::type>::type
790 template<typename _Tp>
791 struct __is_nt_destructible_safe<_Tp, true, false>
792 : public false_type { };
794 template<typename _Tp>
795 struct __is_nt_destructible_safe<_Tp, false, true>
796 : public true_type { };
798 /// is_nothrow_destructible
799 template<typename _Tp>
800 struct is_nothrow_destructible
801 : public __is_nt_destructible_safe<_Tp>::type
804 struct __do_is_default_constructible_impl
806 template<typename _Tp, typename = decltype(_Tp())>
807 static true_type __test(int);
810 static false_type __test(...);
813 template<typename _Tp>
814 struct __is_default_constructible_impl
815 : public __do_is_default_constructible_impl
817 typedef decltype(__test<_Tp>(0)) type;
820 template<typename _Tp>
821 struct __is_default_constructible_atom
822 : public __and_<__not_<is_void<_Tp>>,
823 __is_default_constructible_impl<_Tp>>::type
826 template<typename _Tp, bool = is_array<_Tp>::value>
827 struct __is_default_constructible_safe;
829 // The following technique is a workaround for a current core language
830 // restriction, which does not allow for array types to occur in
831 // functional casts of the form T(). Complete arrays can be default-
832 // constructed, if the element type is default-constructible, but
833 // arrays with unknown bounds are not.
834 template<typename _Tp>
835 struct __is_default_constructible_safe<_Tp, true>
836 : public __and_<__is_array_known_bounds<_Tp>,
837 __is_default_constructible_atom<typename
838 remove_all_extents<_Tp>::type>>::type
841 template<typename _Tp>
842 struct __is_default_constructible_safe<_Tp, false>
843 : public __is_default_constructible_atom<_Tp>::type
846 /// is_default_constructible
847 template<typename _Tp>
848 struct is_default_constructible
849 : public __is_default_constructible_safe<_Tp>::type
853 // Implementation of is_constructible.
855 // The hardest part of this trait is the binary direct-initialization
856 // case, because we hit into a functional cast of the form T(arg).
857 // This implementation uses different strategies depending on the
858 // target type to reduce the test overhead as much as possible:
860 // a) For a reference target type, we use a static_cast expression
861 // modulo its extra cases.
863 // b) For a non-reference target type we use a ::new expression.
864 struct __do_is_static_castable_impl
866 template<typename _From, typename _To, typename
867 = decltype(static_cast<_To>(declval<_From>()))>
868 static true_type __test(int);
870 template<typename, typename>
871 static false_type __test(...);
874 template<typename _From, typename _To>
875 struct __is_static_castable_impl
876 : public __do_is_static_castable_impl
878 typedef decltype(__test<_From, _To>(0)) type;
881 template<typename _From, typename _To>
882 struct __is_static_castable_safe
883 : public __is_static_castable_impl<_From, _To>::type
886 // __is_static_castable
887 template<typename _From, typename _To>
888 struct __is_static_castable
889 : public integral_constant<bool, (__is_static_castable_safe<
893 // Implementation for non-reference types. To meet the proper
894 // variable definition semantics, we also need to test for
895 // is_destructible in this case.
896 // This form should be simplified by a single expression:
897 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
898 struct __do_is_direct_constructible_impl
900 template<typename _Tp, typename _Arg, typename
901 = decltype(::new _Tp(declval<_Arg>()))>
902 static true_type __test(int);
904 template<typename, typename>
905 static false_type __test(...);
908 template<typename _Tp, typename _Arg>
909 struct __is_direct_constructible_impl
910 : public __do_is_direct_constructible_impl
912 typedef decltype(__test<_Tp, _Arg>(0)) type;
915 template<typename _Tp, typename _Arg>
916 struct __is_direct_constructible_new_safe
917 : public __and_<is_destructible<_Tp>,
918 __is_direct_constructible_impl<_Tp, _Arg>>::type
921 template<typename, typename>
924 template<typename, typename>
928 struct remove_reference;
930 template<typename _From, typename _To, bool
931 = __not_<__or_<is_void<_From>,
932 is_function<_From>>>::value>
933 struct __is_base_to_derived_ref;
935 // Detect whether we have a downcast situation during
936 // reference binding.
937 template<typename _From, typename _To>
938 struct __is_base_to_derived_ref<_From, _To, true>
940 typedef typename remove_cv<typename remove_reference<_From
941 >::type>::type __src_t;
942 typedef typename remove_cv<typename remove_reference<_To
943 >::type>::type __dst_t;
944 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
945 is_base_of<__src_t, __dst_t>> type;
946 static constexpr bool value = type::value;
949 template<typename _From, typename _To>
950 struct __is_base_to_derived_ref<_From, _To, false>
954 template<typename _From, typename _To, bool
955 = __and_<is_lvalue_reference<_From>,
956 is_rvalue_reference<_To>>::value>
957 struct __is_lvalue_to_rvalue_ref;
959 // Detect whether we have an lvalue of non-function type
960 // bound to a reference-compatible rvalue-reference.
961 template<typename _From, typename _To>
962 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
964 typedef typename remove_cv<typename remove_reference<
965 _From>::type>::type __src_t;
966 typedef typename remove_cv<typename remove_reference<
967 _To>::type>::type __dst_t;
968 typedef __and_<__not_<is_function<__src_t>>,
969 __or_<is_same<__src_t, __dst_t>,
970 is_base_of<__dst_t, __src_t>>> type;
971 static constexpr bool value = type::value;
974 template<typename _From, typename _To>
975 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
979 // Here we handle direct-initialization to a reference type as
980 // equivalent to a static_cast modulo overshooting conversions.
981 // These are restricted to the following conversions:
982 // a) A base class value to a derived class reference
983 // b) An lvalue to an rvalue-reference of reference-compatible
984 // types that are not functions
985 template<typename _Tp, typename _Arg>
986 struct __is_direct_constructible_ref_cast
987 : public __and_<__is_static_castable<_Arg, _Tp>,
988 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
989 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
993 template<typename _Tp, typename _Arg>
994 struct __is_direct_constructible_new
995 : public conditional<is_reference<_Tp>::value,
996 __is_direct_constructible_ref_cast<_Tp, _Arg>,
997 __is_direct_constructible_new_safe<_Tp, _Arg>
1001 template<typename _Tp, typename _Arg>
1002 struct __is_direct_constructible
1003 : public __is_direct_constructible_new<_Tp, _Arg>::type
1006 // Since default-construction and binary direct-initialization have
1007 // been handled separately, the implementation of the remaining
1008 // n-ary construction cases is rather straightforward. We can use
1009 // here a functional cast, because array types are excluded anyway
1010 // and this form is never interpreted as a C cast.
1011 struct __do_is_nary_constructible_impl
1013 template<typename _Tp, typename... _Args, typename
1014 = decltype(_Tp(declval<_Args>()...))>
1015 static true_type __test(int);
1017 template<typename, typename...>
1018 static false_type __test(...);
1021 template<typename _Tp, typename... _Args>
1022 struct __is_nary_constructible_impl
1023 : public __do_is_nary_constructible_impl
1025 typedef decltype(__test<_Tp, _Args...>(0)) type;
1028 template<typename _Tp, typename... _Args>
1029 struct __is_nary_constructible
1030 : public __is_nary_constructible_impl<_Tp, _Args...>::type
1032 static_assert(sizeof...(_Args) > 1,
1033 "Only useful for > 1 arguments");
1036 template<typename _Tp, typename... _Args>
1037 struct __is_constructible_impl
1038 : public __is_nary_constructible<_Tp, _Args...>
1041 template<typename _Tp, typename _Arg>
1042 struct __is_constructible_impl<_Tp, _Arg>
1043 : public __is_direct_constructible<_Tp, _Arg>
1046 template<typename _Tp>
1047 struct __is_constructible_impl<_Tp>
1048 : public is_default_constructible<_Tp>
1051 /// is_constructible
1052 template<typename _Tp, typename... _Args>
1053 struct is_constructible
1054 : public __is_constructible_impl<_Tp, _Args...>::type
1057 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1058 struct __is_copy_constructible_impl;
1060 template<typename _Tp>
1061 struct __is_copy_constructible_impl<_Tp, false>
1062 : public false_type { };
1064 template<typename _Tp>
1065 struct __is_copy_constructible_impl<_Tp, true>
1066 : public is_constructible<_Tp, const _Tp&>
1069 /// is_copy_constructible
1070 template<typename _Tp>
1071 struct is_copy_constructible
1072 : public __is_copy_constructible_impl<_Tp>
1075 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1076 struct __is_move_constructible_impl;
1078 template<typename _Tp>
1079 struct __is_move_constructible_impl<_Tp, false>
1080 : public false_type { };
1082 template<typename _Tp>
1083 struct __is_move_constructible_impl<_Tp, true>
1084 : public is_constructible<_Tp, _Tp&&>
1087 /// is_move_constructible
1088 template<typename _Tp>
1089 struct is_move_constructible
1090 : public __is_move_constructible_impl<_Tp>
1093 template<typename _Tp>
1094 struct __is_nt_default_constructible_atom
1095 : public integral_constant<bool, noexcept(_Tp())>
1098 template<typename _Tp, bool = is_array<_Tp>::value>
1099 struct __is_nt_default_constructible_impl;
1101 template<typename _Tp>
1102 struct __is_nt_default_constructible_impl<_Tp, true>
1103 : public __and_<__is_array_known_bounds<_Tp>,
1104 __is_nt_default_constructible_atom<typename
1105 remove_all_extents<_Tp>::type>>::type
1108 template<typename _Tp>
1109 struct __is_nt_default_constructible_impl<_Tp, false>
1110 : public __is_nt_default_constructible_atom<_Tp>
1113 /// is_nothrow_default_constructible
1114 template<typename _Tp>
1115 struct is_nothrow_default_constructible
1116 : public __and_<is_default_constructible<_Tp>,
1117 __is_nt_default_constructible_impl<_Tp>>::type
1120 template<typename _Tp, typename... _Args>
1121 struct __is_nt_constructible_impl
1122 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1125 template<typename _Tp, typename _Arg>
1126 struct __is_nt_constructible_impl<_Tp, _Arg>
1127 : public integral_constant<bool,
1128 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1131 template<typename _Tp>
1132 struct __is_nt_constructible_impl<_Tp>
1133 : public is_nothrow_default_constructible<_Tp>
1136 /// is_nothrow_constructible
1137 template<typename _Tp, typename... _Args>
1138 struct is_nothrow_constructible
1139 : public __and_<is_constructible<_Tp, _Args...>,
1140 __is_nt_constructible_impl<_Tp, _Args...>>::type
1143 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1144 struct __is_nothrow_copy_constructible_impl;
1146 template<typename _Tp>
1147 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1148 : public false_type { };
1150 template<typename _Tp>
1151 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1152 : public is_nothrow_constructible<_Tp, const _Tp&>
1155 /// is_nothrow_copy_constructible
1156 template<typename _Tp>
1157 struct is_nothrow_copy_constructible
1158 : public __is_nothrow_copy_constructible_impl<_Tp>
1161 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1162 struct __is_nothrow_move_constructible_impl;
1164 template<typename _Tp>
1165 struct __is_nothrow_move_constructible_impl<_Tp, false>
1166 : public false_type { };
1168 template<typename _Tp>
1169 struct __is_nothrow_move_constructible_impl<_Tp, true>
1170 : public is_nothrow_constructible<_Tp, _Tp&&>
1173 /// is_nothrow_move_constructible
1174 template<typename _Tp>
1175 struct is_nothrow_move_constructible
1176 : public __is_nothrow_move_constructible_impl<_Tp>
1179 template<typename _Tp, typename _Up>
1180 class __is_assignable_helper
1182 template<typename _Tp1, typename _Up1,
1183 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1187 template<typename, typename>
1192 typedef decltype(__test<_Tp, _Up>(0)) type;
1196 template<typename _Tp, typename _Up>
1197 struct is_assignable
1198 : public __is_assignable_helper<_Tp, _Up>::type
1201 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1202 struct __is_copy_assignable_impl;
1204 template<typename _Tp>
1205 struct __is_copy_assignable_impl<_Tp, false>
1206 : public false_type { };
1208 template<typename _Tp>
1209 struct __is_copy_assignable_impl<_Tp, true>
1210 : public is_assignable<_Tp&, const _Tp&>
1213 /// is_copy_assignable
1214 template<typename _Tp>
1215 struct is_copy_assignable
1216 : public __is_copy_assignable_impl<_Tp>
1219 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1220 struct __is_move_assignable_impl;
1222 template<typename _Tp>
1223 struct __is_move_assignable_impl<_Tp, false>
1224 : public false_type { };
1226 template<typename _Tp>
1227 struct __is_move_assignable_impl<_Tp, true>
1228 : public is_assignable<_Tp&, _Tp&&>
1231 /// is_move_assignable
1232 template<typename _Tp>
1233 struct is_move_assignable
1234 : public __is_move_assignable_impl<_Tp>
1237 template<typename _Tp, typename _Up>
1238 struct __is_nt_assignable_impl
1239 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1242 /// is_nothrow_assignable
1243 template<typename _Tp, typename _Up>
1244 struct is_nothrow_assignable
1245 : public __and_<is_assignable<_Tp, _Up>,
1246 __is_nt_assignable_impl<_Tp, _Up>>::type
1249 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1250 struct __is_nt_copy_assignable_impl;
1252 template<typename _Tp>
1253 struct __is_nt_copy_assignable_impl<_Tp, false>
1254 : public false_type { };
1256 template<typename _Tp>
1257 struct __is_nt_copy_assignable_impl<_Tp, true>
1258 : public is_nothrow_assignable<_Tp&, const _Tp&>
1261 /// is_nothrow_copy_assignable
1262 template<typename _Tp>
1263 struct is_nothrow_copy_assignable
1264 : public __is_nt_copy_assignable_impl<_Tp>
1267 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1268 struct __is_nt_move_assignable_impl;
1270 template<typename _Tp>
1271 struct __is_nt_move_assignable_impl<_Tp, false>
1272 : public false_type { };
1274 template<typename _Tp>
1275 struct __is_nt_move_assignable_impl<_Tp, true>
1276 : public is_nothrow_assignable<_Tp&, _Tp&&>
1279 /// is_nothrow_move_assignable
1280 template<typename _Tp>
1281 struct is_nothrow_move_assignable
1282 : public __is_nt_move_assignable_impl<_Tp>
1285 /// is_trivially_constructible (still unimplemented)
1287 /// is_trivially_default_constructible (still unimplemented)
1289 /// is_trivially_copy_constructible (still unimplemented)
1291 /// is_trivially_move_constructible (still unimplemented)
1293 /// is_trivially_assignable (still unimplemented)
1295 /// is_trivially_copy_assignable (still unimplemented)
1297 /// is_trivially_move_assignable (still unimplemented)
1299 /// is_trivially_destructible
1300 template<typename _Tp>
1301 struct is_trivially_destructible
1302 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1303 __has_trivial_destructor(_Tp)>>::type
1306 /// has_trivial_default_constructor (temporary legacy)
1307 template<typename _Tp>
1308 struct has_trivial_default_constructor
1309 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1312 /// has_trivial_copy_constructor (temporary legacy)
1313 template<typename _Tp>
1314 struct has_trivial_copy_constructor
1315 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1318 /// has_trivial_copy_assign (temporary legacy)
1319 template<typename _Tp>
1320 struct has_trivial_copy_assign
1321 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1324 /// has_virtual_destructor
1325 template<typename _Tp>
1326 struct has_virtual_destructor
1327 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1331 // type property queries.
1334 template<typename _Tp>
1336 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1341 : public integral_constant<std::size_t, 0> { };
1343 template<typename _Tp, std::size_t _Size>
1344 struct rank<_Tp[_Size]>
1345 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1347 template<typename _Tp>
1349 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1352 template<typename, unsigned _Uint>
1354 : public integral_constant<std::size_t, 0> { };
1356 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1357 struct extent<_Tp[_Size], _Uint>
1358 : public integral_constant<std::size_t,
1359 _Uint == 0 ? _Size : extent<_Tp,
1363 template<typename _Tp, unsigned _Uint>
1364 struct extent<_Tp[], _Uint>
1365 : public integral_constant<std::size_t,
1366 _Uint == 0 ? 0 : extent<_Tp,
1374 template<typename, typename>
1376 : public false_type { };
1378 template<typename _Tp>
1379 struct is_same<_Tp, _Tp>
1380 : public true_type { };
1383 template<typename _Base, typename _Derived>
1385 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1388 template<typename _From, typename _To,
1389 bool = __or_<is_void<_From>, is_function<_To>,
1390 is_array<_To>>::value>
1391 struct __is_convertible_helper
1392 { typedef typename is_void<_To>::type type; };
1394 template<typename _From, typename _To>
1395 class __is_convertible_helper<_From, _To, false>
1397 template<typename _To1>
1398 static void __test_aux(_To1);
1400 template<typename _From1, typename _To1,
1401 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1405 template<typename, typename>
1410 typedef decltype(__test<_From, _To>(0)) type;
1415 template<typename _From, typename _To>
1416 struct is_convertible
1417 : public __is_convertible_helper<_From, _To>::type
1421 // Const-volatile modifications.
1424 template<typename _Tp>
1426 { typedef _Tp type; };
1428 template<typename _Tp>
1429 struct remove_const<_Tp const>
1430 { typedef _Tp type; };
1433 template<typename _Tp>
1434 struct remove_volatile
1435 { typedef _Tp type; };
1437 template<typename _Tp>
1438 struct remove_volatile<_Tp volatile>
1439 { typedef _Tp type; };
1442 template<typename _Tp>
1446 remove_const<typename remove_volatile<_Tp>::type>::type type;
1450 template<typename _Tp>
1452 { typedef _Tp const type; };
1455 template<typename _Tp>
1457 { typedef _Tp volatile type; };
1460 template<typename _Tp>
1464 add_const<typename add_volatile<_Tp>::type>::type type;
1467 #if __cplusplus > 201103L
1469 #define __cpp_lib_transformation_trait_aliases 201304
1471 /// Alias template for remove_const
1472 template<typename _Tp>
1473 using remove_const_t = typename remove_const<_Tp>::type;
1475 /// Alias template for remove_volatile
1476 template<typename _Tp>
1477 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1479 /// Alias template for remove_cv
1480 template<typename _Tp>
1481 using remove_cv_t = typename remove_cv<_Tp>::type;
1483 /// Alias template for add_const
1484 template<typename _Tp>
1485 using add_const_t = typename add_const<_Tp>::type;
1487 /// Alias template for add_volatile
1488 template<typename _Tp>
1489 using add_volatile_t = typename add_volatile<_Tp>::type;
1491 /// Alias template for add_cv
1492 template<typename _Tp>
1493 using add_cv_t = typename add_cv<_Tp>::type;
1496 // Reference transformations.
1498 /// remove_reference
1499 template<typename _Tp>
1500 struct remove_reference
1501 { typedef _Tp type; };
1503 template<typename _Tp>
1504 struct remove_reference<_Tp&>
1505 { typedef _Tp type; };
1507 template<typename _Tp>
1508 struct remove_reference<_Tp&&>
1509 { typedef _Tp type; };
1511 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1512 struct __add_lvalue_reference_helper
1513 { typedef _Tp type; };
1515 template<typename _Tp>
1516 struct __add_lvalue_reference_helper<_Tp, true>
1517 { typedef _Tp& type; };
1519 /// add_lvalue_reference
1520 template<typename _Tp>
1521 struct add_lvalue_reference
1522 : public __add_lvalue_reference_helper<_Tp>
1525 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1526 struct __add_rvalue_reference_helper
1527 { typedef _Tp type; };
1529 template<typename _Tp>
1530 struct __add_rvalue_reference_helper<_Tp, true>
1531 { typedef _Tp&& type; };
1533 /// add_rvalue_reference
1534 template<typename _Tp>
1535 struct add_rvalue_reference
1536 : public __add_rvalue_reference_helper<_Tp>
1539 #if __cplusplus > 201103L
1540 /// Alias template for remove_reference
1541 template<typename _Tp>
1542 using remove_reference_t = typename remove_reference<_Tp>::type;
1544 /// Alias template for add_lvalue_reference
1545 template<typename _Tp>
1546 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1548 /// Alias template for add_rvalue_reference
1549 template<typename _Tp>
1550 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1553 // Sign modifications.
1555 // Utility for constructing identically cv-qualified types.
1556 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1557 struct __cv_selector;
1559 template<typename _Unqualified>
1560 struct __cv_selector<_Unqualified, false, false>
1561 { typedef _Unqualified __type; };
1563 template<typename _Unqualified>
1564 struct __cv_selector<_Unqualified, false, true>
1565 { typedef volatile _Unqualified __type; };
1567 template<typename _Unqualified>
1568 struct __cv_selector<_Unqualified, true, false>
1569 { typedef const _Unqualified __type; };
1571 template<typename _Unqualified>
1572 struct __cv_selector<_Unqualified, true, true>
1573 { typedef const volatile _Unqualified __type; };
1575 template<typename _Qualified, typename _Unqualified,
1576 bool _IsConst = is_const<_Qualified>::value,
1577 bool _IsVol = is_volatile<_Qualified>::value>
1578 class __match_cv_qualifiers
1580 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1583 typedef typename __match::__type __type;
1586 // Utility for finding the unsigned versions of signed integral types.
1587 template<typename _Tp>
1588 struct __make_unsigned
1589 { typedef _Tp __type; };
1592 struct __make_unsigned<char>
1593 { typedef unsigned char __type; };
1596 struct __make_unsigned<signed char>
1597 { typedef unsigned char __type; };
1600 struct __make_unsigned<short>
1601 { typedef unsigned short __type; };
1604 struct __make_unsigned<int>
1605 { typedef unsigned int __type; };
1608 struct __make_unsigned<long>
1609 { typedef unsigned long __type; };
1612 struct __make_unsigned<long long>
1613 { typedef unsigned long long __type; };
1615 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1617 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1621 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1623 struct __make_unsigned<__int128>
1624 { typedef unsigned __int128 __type; };
1627 // Select between integral and enum: not possible to be both.
1628 template<typename _Tp,
1629 bool _IsInt = is_integral<_Tp>::value,
1630 bool _IsEnum = is_enum<_Tp>::value>
1631 class __make_unsigned_selector;
1633 template<typename _Tp>
1634 class __make_unsigned_selector<_Tp, true, false>
1636 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1637 typedef typename __unsignedt::__type __unsigned_type;
1638 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1641 typedef typename __cv_unsigned::__type __type;
1644 template<typename _Tp>
1645 class __make_unsigned_selector<_Tp, false, true>
1647 // With -fshort-enums, an enum may be as small as a char.
1648 typedef unsigned char __smallest;
1649 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1650 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1651 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1652 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1653 typedef typename __cond2::type __cond2_type;
1654 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1655 typedef typename __cond1::type __cond1_type;
1658 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1661 // Given an integral/enum type, return the corresponding unsigned
1663 // Primary template.
1665 template<typename _Tp>
1666 struct make_unsigned
1667 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1669 // Integral, but don't define.
1671 struct make_unsigned<bool>;
1674 // Utility for finding the signed versions of unsigned integral types.
1675 template<typename _Tp>
1676 struct __make_signed
1677 { typedef _Tp __type; };
1680 struct __make_signed<char>
1681 { typedef signed char __type; };
1684 struct __make_signed<unsigned char>
1685 { typedef signed char __type; };
1688 struct __make_signed<unsigned short>
1689 { typedef signed short __type; };
1692 struct __make_signed<unsigned int>
1693 { typedef signed int __type; };
1696 struct __make_signed<unsigned long>
1697 { typedef signed long __type; };
1700 struct __make_signed<unsigned long long>
1701 { typedef signed long long __type; };
1703 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1705 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1709 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1711 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1714 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1718 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1720 struct __make_signed<unsigned __int128>
1721 { typedef __int128 __type; };
1724 // Select between integral and enum: not possible to be both.
1725 template<typename _Tp,
1726 bool _IsInt = is_integral<_Tp>::value,
1727 bool _IsEnum = is_enum<_Tp>::value>
1728 class __make_signed_selector;
1730 template<typename _Tp>
1731 class __make_signed_selector<_Tp, true, false>
1733 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1734 typedef typename __signedt::__type __signed_type;
1735 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1738 typedef typename __cv_signed::__type __type;
1741 template<typename _Tp>
1742 class __make_signed_selector<_Tp, false, true>
1744 // With -fshort-enums, an enum may be as small as a char.
1745 typedef signed char __smallest;
1746 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1747 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1748 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1749 typedef conditional<__b2, signed int, signed long> __cond2;
1750 typedef typename __cond2::type __cond2_type;
1751 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1752 typedef typename __cond1::type __cond1_type;
1755 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1758 // Given an integral/enum type, return the corresponding signed
1760 // Primary template.
1762 template<typename _Tp>
1764 { typedef typename __make_signed_selector<_Tp>::__type type; };
1766 // Integral, but don't define.
1768 struct make_signed<bool>;
1770 #if __cplusplus > 201103L
1771 /// Alias template for make_signed
1772 template<typename _Tp>
1773 using make_signed_t = typename make_signed<_Tp>::type;
1775 /// Alias template for make_unsigned
1776 template<typename _Tp>
1777 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1780 // Array modifications.
1783 template<typename _Tp>
1784 struct remove_extent
1785 { typedef _Tp type; };
1787 template<typename _Tp, std::size_t _Size>
1788 struct remove_extent<_Tp[_Size]>
1789 { typedef _Tp type; };
1791 template<typename _Tp>
1792 struct remove_extent<_Tp[]>
1793 { typedef _Tp type; };
1795 /// remove_all_extents
1796 template<typename _Tp>
1797 struct remove_all_extents
1798 { typedef _Tp type; };
1800 template<typename _Tp, std::size_t _Size>
1801 struct remove_all_extents<_Tp[_Size]>
1802 { typedef typename remove_all_extents<_Tp>::type type; };
1804 template<typename _Tp>
1805 struct remove_all_extents<_Tp[]>
1806 { typedef typename remove_all_extents<_Tp>::type type; };
1808 #if __cplusplus > 201103L
1809 /// Alias template for remove_extent
1810 template<typename _Tp>
1811 using remove_extent_t = typename remove_extent<_Tp>::type;
1813 /// Alias template for remove_all_extents
1814 template<typename _Tp>
1815 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1818 // Pointer modifications.
1820 template<typename _Tp, typename>
1821 struct __remove_pointer_helper
1822 { typedef _Tp type; };
1824 template<typename _Tp, typename _Up>
1825 struct __remove_pointer_helper<_Tp, _Up*>
1826 { typedef _Up type; };
1829 template<typename _Tp>
1830 struct remove_pointer
1831 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1835 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1836 is_void<_Tp>>::value>
1837 struct __add_pointer_helper
1838 { typedef _Tp type; };
1840 template<typename _Tp>
1841 struct __add_pointer_helper<_Tp, true>
1842 { typedef typename remove_reference<_Tp>::type* type; };
1844 template<typename _Tp>
1846 : public __add_pointer_helper<_Tp>
1849 #if __cplusplus > 201103L
1850 /// Alias template for remove_pointer
1851 template<typename _Tp>
1852 using remove_pointer_t = typename remove_pointer<_Tp>::type;
1854 /// Alias template for add_pointer
1855 template<typename _Tp>
1856 using add_pointer_t = typename add_pointer<_Tp>::type;
1859 template<std::size_t _Len>
1860 struct __aligned_storage_msa
1864 unsigned char __data[_Len];
1865 struct __attribute__((__aligned__)) { } __align;
1870 * @brief Alignment type.
1872 * The value of _Align is a default-alignment which shall be the
1873 * most stringent alignment requirement for any C++ object type
1874 * whose size is no greater than _Len (3.9). The member typedef
1875 * type shall be a POD type suitable for use as uninitialized
1876 * storage for any object whose size is at most _Len and whose
1877 * alignment is a divisor of _Align.
1879 template<std::size_t _Len, std::size_t _Align =
1880 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1881 struct aligned_storage
1885 unsigned char __data[_Len];
1886 struct __attribute__((__aligned__((_Align)))) { } __align;
1891 // Decay trait for arrays and functions, used for perfect forwarding
1892 // in make_pair, make_tuple, etc.
1893 template<typename _Up,
1894 bool _IsArray = is_array<_Up>::value,
1895 bool _IsFunction = is_function<_Up>::value>
1896 struct __decay_selector;
1899 template<typename _Up>
1900 struct __decay_selector<_Up, false, false>
1901 { typedef typename remove_cv<_Up>::type __type; };
1903 template<typename _Up>
1904 struct __decay_selector<_Up, true, false>
1905 { typedef typename remove_extent<_Up>::type* __type; };
1907 template<typename _Up>
1908 struct __decay_selector<_Up, false, true>
1909 { typedef typename add_pointer<_Up>::type __type; };
1912 template<typename _Tp>
1915 typedef typename remove_reference<_Tp>::type __remove_type;
1918 typedef typename __decay_selector<__remove_type>::__type type;
1921 template<typename _Tp>
1922 class reference_wrapper;
1924 // Helper which adds a reference to a type when given a reference_wrapper
1925 template<typename _Tp>
1926 struct __strip_reference_wrapper
1931 template<typename _Tp>
1932 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1934 typedef _Tp& __type;
1937 template<typename _Tp>
1938 struct __decay_and_strip
1940 typedef typename __strip_reference_wrapper<
1941 typename decay<_Tp>::type>::__type __type;
1945 // Primary template.
1946 /// Define a member typedef @c type only if a boolean constant is true.
1947 template<bool, typename _Tp = void>
1951 // Partial specialization for true.
1952 template<typename _Tp>
1953 struct enable_if<true, _Tp>
1954 { typedef _Tp type; };
1956 template<typename... _Cond>
1957 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
1959 // Primary template.
1960 /// Define a member typedef @c type to one of two argument types.
1961 template<bool _Cond, typename _Iftrue, typename _Iffalse>
1963 { typedef _Iftrue type; };
1965 // Partial specialization for false.
1966 template<typename _Iftrue, typename _Iffalse>
1967 struct conditional<false, _Iftrue, _Iffalse>
1968 { typedef _Iffalse type; };
1971 template<typename... _Tp>
1974 // Sfinae-friendly common_type implementation:
1976 struct __do_common_type_impl
1978 template<typename _Tp, typename _Up>
1979 static __success_type<typename decay<decltype
1980 (true ? std::declval<_Tp>()
1981 : std::declval<_Up>())>::type> _S_test(int);
1983 template<typename, typename>
1984 static __failure_type _S_test(...);
1987 template<typename _Tp, typename _Up>
1988 struct __common_type_impl
1989 : private __do_common_type_impl
1991 typedef decltype(_S_test<_Tp, _Up>(0)) type;
1994 struct __do_member_type_wrapper
1996 template<typename _Tp>
1997 static __success_type<typename _Tp::type> _S_test(int);
2000 static __failure_type _S_test(...);
2003 template<typename _Tp>
2004 struct __member_type_wrapper
2005 : private __do_member_type_wrapper
2007 typedef decltype(_S_test<_Tp>(0)) type;
2010 template<typename _CTp, typename... _Args>
2011 struct __expanded_common_type_wrapper
2013 typedef common_type<typename _CTp::type, _Args...> type;
2016 template<typename... _Args>
2017 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2018 { typedef __failure_type type; };
2020 template<typename _Tp>
2021 struct common_type<_Tp>
2022 { typedef typename decay<_Tp>::type type; };
2024 template<typename _Tp, typename _Up>
2025 struct common_type<_Tp, _Up>
2026 : public __common_type_impl<_Tp, _Up>::type
2029 template<typename _Tp, typename _Up, typename... _Vp>
2030 struct common_type<_Tp, _Up, _Vp...>
2031 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2032 common_type<_Tp, _Up>>::type, _Vp...>::type
2035 /// The underlying type of an enum.
2036 template<typename _Tp>
2037 struct underlying_type
2039 typedef __underlying_type(_Tp) type;
2042 template<typename _Tp>
2043 struct __declval_protector
2045 static const bool __stop = false;
2046 static typename add_rvalue_reference<_Tp>::type __delegate();
2049 template<typename _Tp>
2050 inline typename add_rvalue_reference<_Tp>::type
2053 static_assert(__declval_protector<_Tp>::__stop,
2054 "declval() must not be used!");
2055 return __declval_protector<_Tp>::__delegate();
2059 template<typename _Signature>
2062 // Sfinae-friendly result_of implementation:
2064 #define __cpp_lib_result_of_sfinae 201210
2066 // [func.require] paragraph 1 bullet 1:
2067 struct __result_of_memfun_ref_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_ref
2080 : private __result_of_memfun_ref_impl
2082 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2085 // [func.require] paragraph 1 bullet 2:
2086 struct __result_of_memfun_deref_impl
2088 template<typename _Fp, typename _Tp1, typename... _Args>
2089 static __success_type<decltype(
2090 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2093 template<typename...>
2094 static __failure_type _S_test(...);
2097 template<typename _MemPtr, typename _Arg, typename... _Args>
2098 struct __result_of_memfun_deref
2099 : private __result_of_memfun_deref_impl
2101 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2104 // [func.require] paragraph 1 bullet 3:
2105 struct __result_of_memobj_ref_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_ref
2118 : private __result_of_memobj_ref_impl
2120 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2123 // [func.require] paragraph 1 bullet 4:
2124 struct __result_of_memobj_deref_impl
2126 template<typename _Fp, typename _Tp1>
2127 static __success_type<decltype(
2128 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2131 template<typename, typename>
2132 static __failure_type _S_test(...);
2135 template<typename _MemPtr, typename _Arg>
2136 struct __result_of_memobj_deref
2137 : private __result_of_memobj_deref_impl
2139 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2142 template<typename _MemPtr, typename _Arg>
2143 struct __result_of_memobj;
2145 template<typename _Res, typename _Class, typename _Arg>
2146 struct __result_of_memobj<_Res _Class::*, _Arg>
2148 typedef typename remove_cv<typename remove_reference<
2149 _Arg>::type>::type _Argval;
2150 typedef _Res _Class::* _MemPtr;
2151 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2152 is_base_of<_Class, _Argval>>::value,
2153 __result_of_memobj_ref<_MemPtr, _Arg>,
2154 __result_of_memobj_deref<_MemPtr, _Arg>
2158 template<typename _MemPtr, typename _Arg, typename... _Args>
2159 struct __result_of_memfun;
2161 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2162 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2164 typedef typename remove_cv<typename remove_reference<
2165 _Arg>::type>::type _Argval;
2166 typedef _Res _Class::* _MemPtr;
2167 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2168 is_base_of<_Class, _Argval>>::value,
2169 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2170 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2174 template<bool, bool, typename _Functor, typename... _ArgTypes>
2175 struct __result_of_impl
2177 typedef __failure_type type;
2180 template<typename _MemPtr, typename _Arg>
2181 struct __result_of_impl<true, false, _MemPtr, _Arg>
2182 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2185 template<typename _MemPtr, typename _Arg, typename... _Args>
2186 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2187 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2190 // [func.require] paragraph 1 bullet 5:
2191 struct __result_of_other_impl
2193 template<typename _Fn, typename... _Args>
2194 static __success_type<decltype(
2195 std::declval<_Fn>()(std::declval<_Args>()...)
2198 template<typename...>
2199 static __failure_type _S_test(...);
2202 template<typename _Functor, typename... _ArgTypes>
2203 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2204 : private __result_of_other_impl
2206 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2209 template<typename _Functor, typename... _ArgTypes>
2210 struct result_of<_Functor(_ArgTypes...)>
2211 : public __result_of_impl<
2212 is_member_object_pointer<
2213 typename remove_reference<_Functor>::type
2215 is_member_function_pointer<
2216 typename remove_reference<_Functor>::type
2218 _Functor, _ArgTypes...
2222 #if __cplusplus > 201103L
2223 /// Alias template for aligned_storage
2224 template<size_t _Len, size_t _Align =
2225 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2226 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2228 /// Alias template for decay
2229 template<typename _Tp>
2230 using decay_t = typename decay<_Tp>::type;
2232 /// Alias template for enable_if
2233 template<bool _Cond, typename _Tp = void>
2234 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2236 /// Alias template for conditional
2237 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2238 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2240 /// Alias template for common_type
2241 template<typename... _Tp>
2242 using common_type_t = typename common_type<_Tp...>::type;
2244 /// Alias template for underlying_type
2245 template<typename _Tp>
2246 using underlying_type_t = typename underlying_type<_Tp>::type;
2248 /// Alias template for result_of
2249 template<typename _Tp>
2250 using result_of_t = typename result_of<_Tp>::type;
2253 /// @} group metaprogramming
2256 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2257 * member type _NTYPE.
2259 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2260 template<typename _Tp> \
2261 class __has_##_NTYPE##_helper \
2263 template<typename _Up> \
2267 template<typename _Up> \
2268 static true_type __test(_Wrap_type<typename _Up::_NTYPE>*); \
2270 template<typename _Up> \
2271 static false_type __test(...); \
2274 typedef decltype(__test<_Tp>(0)) type; \
2277 template<typename _Tp> \
2278 struct __has_##_NTYPE \
2279 : public __has_##_NTYPE##_helper \
2280 <typename remove_cv<_Tp>::type>::type \
2283 _GLIBCXX_END_NAMESPACE_VERSION
2288 #endif // _GLIBCXX_TYPE_TRAITS