Commit 77d45108 by Paolo Carlini Committed by Paolo Carlini

type_traits (_DEFINE_SPEC*): Simplify.

2008-08-10  Paolo Carlini  <paolo.carlini@oracle.com>

	* 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
parent d47c3b4e
2008-08-10 Paolo Carlini <paolo.carlini@oracle.com>
* 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 <paolo.carlini@oracle.com> 2008-08-09 Paolo Carlini <paolo.carlini@oracle.com>
Revert fix for libstdc++/35637, thanks to other/36901. Revert fix for libstdc++/35637, thanks to other/36901.
......
// TR1 type_traits -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -60,17 +60,11 @@ namespace std ...@@ -60,17 +60,11 @@ namespace std
{ {
namespace tr1 namespace tr1
{ {
#define _DEFINE_SPEC_HELPER(_Spec) \ #define _DEFINE_SPEC(_Trait, _Type) \
template<> \ template<> \
struct _Spec \ struct _Trait<_Type> \
: public true_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<typename> template<typename>
struct is_reference struct is_reference
: public false_type { }; : public false_type { };
...@@ -120,22 +114,34 @@ namespace tr1 ...@@ -120,22 +114,34 @@ namespace tr1
{ }; { };
template<typename> template<typename>
struct is_signed struct __is_signed_helper
: public false_type { }; : public false_type { };
_DEFINE_SPEC(is_signed, signed char) _DEFINE_SPEC(__is_signed_helper, signed char)
_DEFINE_SPEC(is_signed, short) _DEFINE_SPEC(__is_signed_helper, short)
_DEFINE_SPEC(is_signed, int) _DEFINE_SPEC(__is_signed_helper, int)
_DEFINE_SPEC(is_signed, long) _DEFINE_SPEC(__is_signed_helper, long)
_DEFINE_SPEC(is_signed, long long) _DEFINE_SPEC(__is_signed_helper, long long)
template<typename _Tp>
struct is_signed
: public integral_constant<bool, (__is_signed_helper<typename
remove_cv<_Tp>::type>::value)>
{ };
template<typename> template<typename>
struct is_unsigned struct __is_unsigned_helper
: public false_type { }; : public false_type { };
_DEFINE_SPEC(is_unsigned, unsigned char) _DEFINE_SPEC(__is_unsigned_helper, unsigned char)
_DEFINE_SPEC(is_unsigned, unsigned short) _DEFINE_SPEC(__is_unsigned_helper, unsigned short)
_DEFINE_SPEC(is_unsigned, unsigned int) _DEFINE_SPEC(__is_unsigned_helper, unsigned int)
_DEFINE_SPEC(is_unsigned, unsigned long) _DEFINE_SPEC(__is_unsigned_helper, unsigned long)
_DEFINE_SPEC(is_unsigned, unsigned long long) _DEFINE_SPEC(__is_unsigned_helper, unsigned long long)
template<typename _Tp>
struct is_unsigned
: public integral_constant<bool, (__is_unsigned_helper<typename
remove_cv<_Tp>::type>::value)>
{ };
template<typename _Base, typename _Derived> template<typename _Base, typename _Derived>
struct __is_base_of_helper struct __is_base_of_helper
...@@ -241,7 +247,6 @@ namespace tr1 ...@@ -241,7 +247,6 @@ namespace tr1
}; };
}; };
#undef _DEFINE_SPEC_HELPER
#undef _DEFINE_SPEC #undef _DEFINE_SPEC
} }
} }
......
...@@ -43,29 +43,19 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -43,29 +43,19 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
typedef struct { char __arr[2]; } __two; typedef struct { char __arr[2]; } __two;
}; };
#define _DEFINE_SPEC_BODY(_Value) \ #define _DEFINE_SPEC_0_HELPER \
: public integral_constant<bool, _Value> { }; template<>
#define _DEFINE_SPEC_1_HELPER \
template<typename _Tp>
#define _DEFINE_SPEC_2_HELPER \
template<typename _Tp, typename _Cp>
#define _DEFINE_SPEC_0_HELPER(_Spec, _Value) \ #define _DEFINE_SPEC(_Order, _Trait, _Type, _Value) \
template<> \ _DEFINE_SPEC_##_Order##_HELPER \
struct _Spec \ struct _Trait<_Type> \
_DEFINE_SPEC_BODY(_Value) : public integral_constant<bool, _Value> { };
#define _DEFINE_SPEC_1_HELPER(_Spec, _Value) \
template<typename _Tp> \
struct _Spec \
_DEFINE_SPEC_BODY(_Value)
#define _DEFINE_SPEC_2_HELPER(_Spec, _Value) \
template<typename _Tp, typename _Cp> \
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)
/// helper classes [4.3]. /// helper classes [4.3].
template<typename _Tp, _Tp __v> template<typename _Tp, _Tp __v>
...@@ -79,49 +69,70 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -79,49 +69,70 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
/// typedef for true_type /// typedef for true_type
typedef integral_constant<bool, true> true_type; typedef integral_constant<bool, true> true_type;
/// typedef for true_type /// typedef for false_type
typedef integral_constant<bool, false> false_type; typedef integral_constant<bool, false> false_type;
template<typename _Tp, _Tp __v> template<typename _Tp, _Tp __v>
const _Tp integral_constant<_Tp, __v>::value; const _Tp integral_constant<_Tp, __v>::value;
/// primary type categories [4.5.1].
template<typename> template<typename>
struct is_void struct remove_cv;
template<typename>
struct __is_void_helper
: public false_type { }; : 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<typename _Tp>
struct is_void
: public integral_constant<bool, (__is_void_helper<typename
remove_cv<_Tp>::type>::value)>
{ };
/// is_integral
template<typename> template<typename>
struct is_integral struct __is_integral_helper
: public false_type { }; : public false_type { };
_DEFINE_SPEC(0, is_integral, bool, true) _DEFINE_SPEC(0, __is_integral_helper, bool, true)
_DEFINE_SPEC(0, is_integral, char, true) _DEFINE_SPEC(0, __is_integral_helper, char, true)
_DEFINE_SPEC(0, is_integral, signed char, true) _DEFINE_SPEC(0, __is_integral_helper, signed char, true)
_DEFINE_SPEC(0, is_integral, unsigned char, true) _DEFINE_SPEC(0, __is_integral_helper, unsigned char, true)
#ifdef _GLIBCXX_USE_WCHAR_T #ifdef _GLIBCXX_USE_WCHAR_T
_DEFINE_SPEC(0, is_integral, wchar_t, true) _DEFINE_SPEC(0, __is_integral_helper, wchar_t, true)
#endif #endif
#ifdef _GLIBCXX_INCLUDE_AS_CXX0X #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
_DEFINE_SPEC(0, is_integral, char16_t, true) _DEFINE_SPEC(0, __is_integral_helper, char16_t, true)
_DEFINE_SPEC(0, is_integral, char32_t, true) _DEFINE_SPEC(0, __is_integral_helper, char32_t, true)
#endif #endif
_DEFINE_SPEC(0, is_integral, short, true) _DEFINE_SPEC(0, __is_integral_helper, short, true)
_DEFINE_SPEC(0, is_integral, unsigned short, true) _DEFINE_SPEC(0, __is_integral_helper, unsigned short, true)
_DEFINE_SPEC(0, is_integral, int, true) _DEFINE_SPEC(0, __is_integral_helper, int, true)
_DEFINE_SPEC(0, is_integral, unsigned int, true) _DEFINE_SPEC(0, __is_integral_helper, unsigned int, true)
_DEFINE_SPEC(0, is_integral, long, true) _DEFINE_SPEC(0, __is_integral_helper, long, true)
_DEFINE_SPEC(0, is_integral, unsigned long, true) _DEFINE_SPEC(0, __is_integral_helper, unsigned long, true)
_DEFINE_SPEC(0, is_integral, long long, true) _DEFINE_SPEC(0, __is_integral_helper, long long, true)
_DEFINE_SPEC(0, is_integral, unsigned long long, true) _DEFINE_SPEC(0, __is_integral_helper, unsigned long long, true)
/// is_integral
template<typename _Tp>
struct is_integral
: public integral_constant<bool, (__is_integral_helper<typename
remove_cv<_Tp>::type>::value)>
{ };
/// is_floating_point
template<typename> template<typename>
struct is_floating_point struct __is_floating_point_helper
: public false_type { }; : public false_type { };
_DEFINE_SPEC(0, is_floating_point, float, true) _DEFINE_SPEC(0, __is_floating_point_helper, float, true)
_DEFINE_SPEC(0, is_floating_point, double, true) _DEFINE_SPEC(0, __is_floating_point_helper, double, true)
_DEFINE_SPEC(0, is_floating_point, long double, true) _DEFINE_SPEC(0, __is_floating_point_helper, long double, true)
/// is_floating_point
template<typename _Tp>
struct is_floating_point
: public integral_constant<bool, (__is_floating_point_helper<typename
remove_cv<_Tp>::type>::value)>
{ };
/// is_array /// is_array
template<typename> template<typename>
...@@ -136,11 +147,17 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -136,11 +147,17 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
struct is_array<_Tp[]> struct is_array<_Tp[]>
: public true_type { }; : public true_type { };
/// is_pointer
template<typename> template<typename>
struct is_pointer struct __is_pointer_helper
: public false_type { }; : public false_type { };
_DEFINE_SPEC(1, is_pointer, _Tp*, true) _DEFINE_SPEC(1, __is_pointer_helper, _Tp*, true)
/// is_pointer
template<typename _Tp>
struct is_pointer
: public integral_constant<bool, (__is_pointer_helper<typename
remove_cv<_Tp>::type>::value)>
{ };
/// is_reference /// is_reference
template<typename _Tp> template<typename _Tp>
...@@ -150,20 +167,32 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -150,20 +167,32 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
template<typename _Tp> template<typename _Tp>
struct is_function; struct is_function;
/// is_member_object_pointer
template<typename> template<typename>
struct is_member_object_pointer struct __is_member_object_pointer_helper
: public false_type { }; : 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_function<_Tp>::value)
/// is_member_function_pointer /// is_member_object_pointer
template<typename _Tp>
struct is_member_object_pointer
: public integral_constant<bool, (__is_member_object_pointer_helper<
typename remove_cv<_Tp>::type>::value)>
{ };
template<typename> template<typename>
struct is_member_function_pointer struct __is_member_function_pointer_helper
: public false_type { }; : 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_function<_Tp>::value)
/// is_member_function_pointer
template<typename _Tp>
struct is_member_function_pointer
: public integral_constant<bool, (__is_member_function_pointer_helper<
typename remove_cv<_Tp>::type>::value)>
{ };
/// is_enum /// is_enum
template<typename _Tp> template<typename _Tp>
struct is_enum struct is_enum
...@@ -182,9 +211,6 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -182,9 +211,6 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
: public integral_constant<bool, __is_class(_Tp)> : public integral_constant<bool, __is_class(_Tp)>
{ }; { };
template<typename _Tp>
struct remove_cv;
template<typename> template<typename>
struct __is_function_helper struct __is_function_helper
: public false_type { }; : public false_type { };
...@@ -412,18 +438,21 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -412,18 +438,21 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
{ typedef typename remove_all_extents<_Tp>::type type; }; { typedef typename remove_all_extents<_Tp>::type type; };
/// pointer modifications [4.7.4]. /// pointer modifications [4.7.4].
#undef _DEFINE_SPEC_BODY template<typename _Tp, typename>
#define _DEFINE_SPEC_BODY(_Value) \ struct __remove_pointer_helper
{ typedef _Tp type; }; { typedef _Tp type; };
template<typename _Tp, typename _Up>
struct __remove_pointer_helper<_Tp, _Up*>
{ typedef _Up type; };
/// remove_pointer /// remove_pointer
template<typename _Tp> template<typename _Tp>
struct remove_pointer struct remove_pointer
{ typedef _Tp type; }; : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
_DEFINE_SPEC(1, remove_pointer, _Tp*, false) { };
/// remove_reference template<typename>
template<typename _Tp>
struct remove_reference; struct remove_reference;
/// add_pointer /// add_pointer
...@@ -435,7 +464,6 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 ...@@ -435,7 +464,6 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
#undef _DEFINE_SPEC_1_HELPER #undef _DEFINE_SPEC_1_HELPER
#undef _DEFINE_SPEC_2_HELPER #undef _DEFINE_SPEC_2_HELPER
#undef _DEFINE_SPEC #undef _DEFINE_SPEC
#undef _DEFINE_SPEC_BODY
_GLIBCXX_END_NAMESPACE_TR1 _GLIBCXX_END_NAMESPACE_TR1
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment