From 0030af8c35588e171e21996026a4b5da57654825 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 10 Jul 2014 15:38:20 +0000 Subject: [PATCH] Support the built-in type-trait support in gcc 4.7 and later. Thanks to Albert Wong for the patch. llvm-svn: 212727 --- libcxx/include/type_traits | 88 ++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 94a7362..4179cd1 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -376,13 +376,9 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&> : public t template struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&&> : public true_type {}; #endif -#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) -#define _LIBCPP_HAS_TYPE_TRAITS -#endif - // is_union -#if __has_feature(is_union) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(is_union) || (_GNUC_VER >= 403) template struct _LIBCPP_TYPE_VIS_ONLY is_union : public integral_constant {}; @@ -397,7 +393,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_union // is_class -#if __has_feature(is_class) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(is_class) || (_GNUC_VER >= 403) template struct _LIBCPP_TYPE_VIS_ONLY is_class : public integral_constant {}; @@ -455,13 +451,13 @@ struct __member_pointer_traits_imp namespace __libcpp_is_member_function_pointer_imp { - template - char __test(typename std::__member_pointer_traits_imp<_Tp, true, false>::_FnType *); + template + char __test(typename std::__member_pointer_traits_imp<_Tp, true, false>::_FnType *); - template - std::__two __test(...); + template + std::__two __test(...); }; - + template struct __libcpp_is_member_function_pointer : public integral_constant(nullptr)) == 1> {}; @@ -484,7 +480,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_member_object_pointer // is_enum -#if __has_feature(is_enum) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(is_enum) || (_GNUC_VER >= 403) template struct _LIBCPP_TYPE_VIS_ONLY is_enum : public integral_constant {}; @@ -797,7 +793,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_base_of : public integral_constant {}; -#else // __has_feature(is_base_of) +#else // _LIBCPP_HAS_IS_BASE_OF namespace __is_base_of_imp { @@ -822,7 +818,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_base_of : public integral_constant::value && sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {}; -#endif // __has_feature(is_base_of) +#endif // _LIBCPP_HAS_IS_BASE_OF // is_convertible @@ -945,7 +941,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_convertible // is_empty -#if __has_feature(is_empty) +#if __has_feature(is_empty) || (_GNUC_VER >= 407) template struct _LIBCPP_TYPE_VIS_ONLY is_empty @@ -996,17 +992,17 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic // has_virtual_destructor -#if __has_feature(has_virtual_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403) template struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor : public integral_constant {}; -#else // _LIBCPP_HAS_TYPE_TRAITS +#else template struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor : public false_type {}; -#endif // _LIBCPP_HAS_TYPE_TRAITS +#endif // alignment_of @@ -2434,7 +2430,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible template struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp> -#if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2563,7 +2559,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructibl // is_trivially_assignable -#if __has_feature(is_trivially_constructible) +#if __has_feature(is_trivially_assignable) template struct is_trivially_assignable @@ -2571,7 +2567,7 @@ struct is_trivially_assignable { }; -#else // !__has_feature(is_trivially_constructible) +#else // !__has_feature(is_trivially_assignable) template struct is_trivially_assignable @@ -2597,7 +2593,7 @@ struct is_trivially_assignable<_Tp&, _Tp&&> #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#endif // !__has_feature(is_trivially_constructible) +#endif // !__has_feature(is_trivially_assignable) // is_trivially_copy_assignable @@ -2619,12 +2615,12 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable // is_trivially_destructible -#if __has_feature(has_trivial_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403) template struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible : public integral_constant {}; -#else // _LIBCPP_HAS_TYPE_TRAITS +#else template struct __libcpp_trivial_destructor : public integral_constant::value || @@ -2633,7 +2629,7 @@ template struct __libcpp_trivial_destructor template struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible : public __libcpp_trivial_destructor::type> {}; -#endif // _LIBCPP_HAS_TYPE_TRAITS +#endif // is_nothrow_constructible @@ -2648,7 +2644,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible #ifndef _LIBCPP_HAS_NO_VARIADICS -#if __has_feature(cxx_noexcept) +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) template struct __libcpp_is_nothrow_constructible; @@ -2686,7 +2682,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp> -#if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2700,7 +2696,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&&> #else struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp> #endif -#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2710,7 +2706,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp> template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&> -#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2720,7 +2716,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&> template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&> -#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2742,7 +2738,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> -#if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2753,7 +2749,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp, __is_construct::__nat> -#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2764,7 +2760,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp, template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&, __is_construct::__nat> -#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2775,7 +2771,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&, template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&, __is_construct::__nat> -#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant #else : integral_constant::value> @@ -2810,7 +2806,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible // is_nothrow_assignable -#if __has_feature(cxx_noexcept) +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) template struct __libcpp_is_nothrow_assignable; @@ -2840,7 +2836,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp> -#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant {}; #else : integral_constant::value> {}; @@ -2848,7 +2844,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp> template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&> -#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant {}; #else : integral_constant::value> {}; @@ -2856,7 +2852,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&> template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&> -#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant {}; #else : integral_constant::value> {}; @@ -2866,7 +2862,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&> template struct is_nothrow_assignable<_Tp&, _Tp&&> -#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant {}; #else : integral_constant::value> {}; @@ -2896,7 +2892,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable // is_nothrow_destructible -#if __has_feature(cxx_noexcept) +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) template struct __libcpp_is_nothrow_destructible; @@ -2953,12 +2949,12 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible // is_pod -#if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#if __has_feature(is_pod) || (_GNUC_VER >= 403) template struct _LIBCPP_TYPE_VIS_ONLY is_pod : public integral_constant {}; -#else // _LIBCPP_HAS_TYPE_TRAITS +#else template struct _LIBCPP_TYPE_VIS_ONLY is_pod : public integral_constant::value && @@ -2966,7 +2962,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_pod is_trivially_copy_assignable<_Tp>::value && is_trivially_destructible<_Tp>::value> {}; -#endif // _LIBCPP_HAS_TYPE_TRAITS +#endif // is_literal_type; @@ -2982,7 +2978,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_literal_type // is_standard_layout; template struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout -#if __has_feature(is_standard_layout) +#if __has_feature(is_standard_layout) || (_GNUC_VER >= 407) : public integral_constant #else : integral_constant::type>::value> @@ -3002,7 +2998,7 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable // is_trivial; template struct _LIBCPP_TYPE_VIS_ONLY is_trivial -#if __has_feature(is_trivial) +#if __has_feature(is_trivial) || (_GNUC_VER >= 407) : public integral_constant #else : integral_constant::value && @@ -3332,7 +3328,7 @@ struct __is_swappable { }; -#if __has_feature(cxx_noexcept) +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) template struct __is_nothrow_swappable_imp -- 2.7.4