From 77d451087596cba90c948eb7c4446f4f9a2a785a Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 10 Aug 2008 10:11:46 +0000 Subject: [PATCH] type_traits (_DEFINE_SPEC*): Simplify. 2008-08-10 Paolo Carlini * include/tr1_impl/type_traits (_DEFINE_SPEC*): Simplify. (_DEFINE_SPEC_BODY): Remove. (__is_void_helper, __is_integral_helper, __is_floating_point_helper, __is_member_object_pointer_helper, __is_member_function_pointer_helper, __remove_pointer_helper): Add. (is_void, is_integral, is_floating_point, is_member_object_pointer, is_member_function_pointer, remove_pointer): Use the latter. * include/tr1/type_traits (_DEFINE_SPEC): Simplify. (_DEFINE_SPEC_HELPER): Remove. (__is_signed_helper, __is_unsigned_helper): Add. (is_signed, is_unsigned): Use the latter. From-SVN: r138925 --- libstdc++-v3/ChangeLog | 14 ++ libstdc++-v3/include/tr1/type_traits | 51 ++++--- libstdc++-v3/include/tr1_impl/type_traits | 162 +++++++++++++--------- 3 files changed, 137 insertions(+), 90 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c96ab5ad519..f674cd6410d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2008-08-10 Paolo Carlini + + * include/tr1_impl/type_traits (_DEFINE_SPEC*): Simplify. + (_DEFINE_SPEC_BODY): Remove. + (__is_void_helper, __is_integral_helper, __is_floating_point_helper, + __is_member_object_pointer_helper, __is_member_function_pointer_helper, + __remove_pointer_helper): Add. + (is_void, is_integral, is_floating_point, is_member_object_pointer, + is_member_function_pointer, remove_pointer): Use the latter. + * include/tr1/type_traits (_DEFINE_SPEC): Simplify. + (_DEFINE_SPEC_HELPER): Remove. + (__is_signed_helper, __is_unsigned_helper): Add. + (is_signed, is_unsigned): Use the latter. + 2008-08-09 Paolo Carlini Revert fix for libstdc++/35637, thanks to other/36901. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 734eec6ab7e..f5cffe88a68 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -1,6 +1,6 @@ // TR1 type_traits -*- C++ -*- -// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -60,17 +60,11 @@ namespace std { namespace tr1 { -#define _DEFINE_SPEC_HELPER(_Spec) \ - template<> \ - struct _Spec \ +#define _DEFINE_SPEC(_Trait, _Type) \ + template<> \ + struct _Trait<_Type> \ : public true_type { }; -#define _DEFINE_SPEC(_Trait, _Type) \ - _DEFINE_SPEC_HELPER(_Trait<_Type>) \ - _DEFINE_SPEC_HELPER(_Trait<_Type const>) \ - _DEFINE_SPEC_HELPER(_Trait<_Type volatile>) \ - _DEFINE_SPEC_HELPER(_Trait<_Type const volatile>) - template struct is_reference : public false_type { }; @@ -120,22 +114,34 @@ namespace tr1 { }; template - struct is_signed + struct __is_signed_helper : public false_type { }; - _DEFINE_SPEC(is_signed, signed char) - _DEFINE_SPEC(is_signed, short) - _DEFINE_SPEC(is_signed, int) - _DEFINE_SPEC(is_signed, long) - _DEFINE_SPEC(is_signed, long long) + _DEFINE_SPEC(__is_signed_helper, signed char) + _DEFINE_SPEC(__is_signed_helper, short) + _DEFINE_SPEC(__is_signed_helper, int) + _DEFINE_SPEC(__is_signed_helper, long) + _DEFINE_SPEC(__is_signed_helper, long long) + + template + struct is_signed + : public integral_constant::type>::value)> + { }; template - struct is_unsigned + struct __is_unsigned_helper : public false_type { }; - _DEFINE_SPEC(is_unsigned, unsigned char) - _DEFINE_SPEC(is_unsigned, unsigned short) - _DEFINE_SPEC(is_unsigned, unsigned int) - _DEFINE_SPEC(is_unsigned, unsigned long) - _DEFINE_SPEC(is_unsigned, unsigned long long) + _DEFINE_SPEC(__is_unsigned_helper, unsigned char) + _DEFINE_SPEC(__is_unsigned_helper, unsigned short) + _DEFINE_SPEC(__is_unsigned_helper, unsigned int) + _DEFINE_SPEC(__is_unsigned_helper, unsigned long) + _DEFINE_SPEC(__is_unsigned_helper, unsigned long long) + + template + struct is_unsigned + : public integral_constant::type>::value)> + { }; template struct __is_base_of_helper @@ -241,7 +247,6 @@ namespace tr1 }; }; -#undef _DEFINE_SPEC_HELPER #undef _DEFINE_SPEC } } diff --git a/libstdc++-v3/include/tr1_impl/type_traits b/libstdc++-v3/include/tr1_impl/type_traits index 3a3d66f1b65..e3b6af51bdc 100644 --- a/libstdc++-v3/include/tr1_impl/type_traits +++ b/libstdc++-v3/include/tr1_impl/type_traits @@ -43,29 +43,19 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 typedef struct { char __arr[2]; } __two; }; -#define _DEFINE_SPEC_BODY(_Value) \ - : public integral_constant { }; +#define _DEFINE_SPEC_0_HELPER \ + template<> + +#define _DEFINE_SPEC_1_HELPER \ + template + +#define _DEFINE_SPEC_2_HELPER \ + template -#define _DEFINE_SPEC_0_HELPER(_Spec, _Value) \ - template<> \ - struct _Spec \ - _DEFINE_SPEC_BODY(_Value) - -#define _DEFINE_SPEC_1_HELPER(_Spec, _Value) \ - template \ - struct _Spec \ - _DEFINE_SPEC_BODY(_Value) - -#define _DEFINE_SPEC_2_HELPER(_Spec, _Value) \ - template \ - struct _Spec \ - _DEFINE_SPEC_BODY(_Value) - -#define _DEFINE_SPEC(_Order, _Trait, _Type, _Value) \ - _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>, _Value) \ - _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>, _Value) \ - _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>, _Value) \ - _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>, _Value) +#define _DEFINE_SPEC(_Order, _Trait, _Type, _Value) \ + _DEFINE_SPEC_##_Order##_HELPER \ + struct _Trait<_Type> \ + : public integral_constant { }; /// helper classes [4.3]. template @@ -79,49 +69,70 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 /// typedef for true_type typedef integral_constant true_type; - /// typedef for true_type + /// typedef for false_type typedef integral_constant false_type; template const _Tp integral_constant<_Tp, __v>::value; - /// primary type categories [4.5.1]. template - struct is_void + struct remove_cv; + + template + struct __is_void_helper : public false_type { }; - _DEFINE_SPEC(0, is_void, void, true) + _DEFINE_SPEC(0, __is_void_helper, void, true) + + /// primary type categories [4.5.1]. + template + struct is_void + : public integral_constant::type>::value)> + { }; - /// is_integral template - struct is_integral + struct __is_integral_helper : public false_type { }; - _DEFINE_SPEC(0, is_integral, bool, true) - _DEFINE_SPEC(0, is_integral, char, true) - _DEFINE_SPEC(0, is_integral, signed char, true) - _DEFINE_SPEC(0, is_integral, unsigned char, true) + _DEFINE_SPEC(0, __is_integral_helper, bool, true) + _DEFINE_SPEC(0, __is_integral_helper, char, true) + _DEFINE_SPEC(0, __is_integral_helper, signed char, true) + _DEFINE_SPEC(0, __is_integral_helper, unsigned char, true) #ifdef _GLIBCXX_USE_WCHAR_T - _DEFINE_SPEC(0, is_integral, wchar_t, true) + _DEFINE_SPEC(0, __is_integral_helper, wchar_t, true) #endif #ifdef _GLIBCXX_INCLUDE_AS_CXX0X - _DEFINE_SPEC(0, is_integral, char16_t, true) - _DEFINE_SPEC(0, is_integral, char32_t, true) + _DEFINE_SPEC(0, __is_integral_helper, char16_t, true) + _DEFINE_SPEC(0, __is_integral_helper, char32_t, true) #endif - _DEFINE_SPEC(0, is_integral, short, true) - _DEFINE_SPEC(0, is_integral, unsigned short, true) - _DEFINE_SPEC(0, is_integral, int, true) - _DEFINE_SPEC(0, is_integral, unsigned int, true) - _DEFINE_SPEC(0, is_integral, long, true) - _DEFINE_SPEC(0, is_integral, unsigned long, true) - _DEFINE_SPEC(0, is_integral, long long, true) - _DEFINE_SPEC(0, is_integral, unsigned long long, true) + _DEFINE_SPEC(0, __is_integral_helper, short, true) + _DEFINE_SPEC(0, __is_integral_helper, unsigned short, true) + _DEFINE_SPEC(0, __is_integral_helper, int, true) + _DEFINE_SPEC(0, __is_integral_helper, unsigned int, true) + _DEFINE_SPEC(0, __is_integral_helper, long, true) + _DEFINE_SPEC(0, __is_integral_helper, unsigned long, true) + _DEFINE_SPEC(0, __is_integral_helper, long long, true) + _DEFINE_SPEC(0, __is_integral_helper, unsigned long long, true) + + /// is_integral + template + struct is_integral + : public integral_constant::type>::value)> + { }; - /// is_floating_point template - struct is_floating_point + struct __is_floating_point_helper : public false_type { }; - _DEFINE_SPEC(0, is_floating_point, float, true) - _DEFINE_SPEC(0, is_floating_point, double, true) - _DEFINE_SPEC(0, is_floating_point, long double, true) + _DEFINE_SPEC(0, __is_floating_point_helper, float, true) + _DEFINE_SPEC(0, __is_floating_point_helper, double, true) + _DEFINE_SPEC(0, __is_floating_point_helper, long double, true) + + /// is_floating_point + template + struct is_floating_point + : public integral_constant::type>::value)> + { }; /// is_array template @@ -136,11 +147,17 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 struct is_array<_Tp[]> : public true_type { }; - /// is_pointer template - struct is_pointer + struct __is_pointer_helper : public false_type { }; - _DEFINE_SPEC(1, is_pointer, _Tp*, true) + _DEFINE_SPEC(1, __is_pointer_helper, _Tp*, true) + + /// is_pointer + template + struct is_pointer + : public integral_constant::type>::value)> + { }; /// is_reference template @@ -150,20 +167,32 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 template struct is_function; - /// is_member_object_pointer template - struct is_member_object_pointer + struct __is_member_object_pointer_helper : public false_type { }; - _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*, + _DEFINE_SPEC(2, __is_member_object_pointer_helper, _Tp _Cp::*, !is_function<_Tp>::value) - /// is_member_function_pointer + /// is_member_object_pointer + template + struct is_member_object_pointer + : public integral_constant::type>::value)> + { }; + template - struct is_member_function_pointer + struct __is_member_function_pointer_helper : public false_type { }; - _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*, + _DEFINE_SPEC(2, __is_member_function_pointer_helper, _Tp _Cp::*, is_function<_Tp>::value) + /// is_member_function_pointer + template + struct is_member_function_pointer + : public integral_constant::type>::value)> + { }; + /// is_enum template struct is_enum @@ -182,9 +211,6 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 : public integral_constant { }; - template - struct remove_cv; - template struct __is_function_helper : public false_type { }; @@ -412,18 +438,21 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 { typedef typename remove_all_extents<_Tp>::type type; }; /// pointer modifications [4.7.4]. -#undef _DEFINE_SPEC_BODY -#define _DEFINE_SPEC_BODY(_Value) \ + template + struct __remove_pointer_helper { typedef _Tp type; }; + template + struct __remove_pointer_helper<_Tp, _Up*> + { typedef _Up type; }; + /// remove_pointer template struct remove_pointer - { typedef _Tp type; }; - _DEFINE_SPEC(1, remove_pointer, _Tp*, false) + : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> + { }; - /// remove_reference - template + template struct remove_reference; /// add_pointer @@ -435,7 +464,6 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 #undef _DEFINE_SPEC_1_HELPER #undef _DEFINE_SPEC_2_HELPER #undef _DEFINE_SPEC -#undef _DEFINE_SPEC_BODY _GLIBCXX_END_NAMESPACE_TR1 } -- 2.30.2