// 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
{
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<typename>
struct is_reference
: public false_type { };
{ };
template<typename>
- 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<typename _Tp>
+ struct is_signed
+ : public integral_constant<bool, (__is_signed_helper<typename
+ remove_cv<_Tp>::type>::value)>
+ { };
template<typename>
- 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<typename _Tp>
+ struct is_unsigned
+ : public integral_constant<bool, (__is_unsigned_helper<typename
+ remove_cv<_Tp>::type>::value)>
+ { };
template<typename _Base, typename _Derived>
struct __is_base_of_helper
};
};
-#undef _DEFINE_SPEC_HELPER
#undef _DEFINE_SPEC
}
}
typedef struct { char __arr[2]; } __two;
};
-#define _DEFINE_SPEC_BODY(_Value) \
- : public integral_constant<bool, _Value> { };
+#define _DEFINE_SPEC_0_HELPER \
+ 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) \
- template<> \
- struct _Spec \
- _DEFINE_SPEC_BODY(_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)
+#define _DEFINE_SPEC(_Order, _Trait, _Type, _Value) \
+ _DEFINE_SPEC_##_Order##_HELPER \
+ struct _Trait<_Type> \
+ : public integral_constant<bool, _Value> { };
/// helper classes [4.3].
template<typename _Tp, _Tp __v>
/// typedef for true_type
typedef integral_constant<bool, true> true_type;
- /// typedef for true_type
+ /// typedef for false_type
typedef integral_constant<bool, false> false_type;
template<typename _Tp, _Tp __v>
const _Tp integral_constant<_Tp, __v>::value;
- /// primary type categories [4.5.1].
template<typename>
- struct is_void
+ struct remove_cv;
+
+ template<typename>
+ 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<typename _Tp>
+ struct is_void
+ : public integral_constant<bool, (__is_void_helper<typename
+ remove_cv<_Tp>::type>::value)>
+ { };
- /// is_integral
template<typename>
- 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<typename _Tp>
+ struct is_integral
+ : public integral_constant<bool, (__is_integral_helper<typename
+ remove_cv<_Tp>::type>::value)>
+ { };
- /// is_floating_point
template<typename>
- 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<typename _Tp>
+ struct is_floating_point
+ : public integral_constant<bool, (__is_floating_point_helper<typename
+ remove_cv<_Tp>::type>::value)>
+ { };
/// is_array
template<typename>
struct is_array<_Tp[]>
: public true_type { };
- /// is_pointer
template<typename>
- 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<typename _Tp>
+ struct is_pointer
+ : public integral_constant<bool, (__is_pointer_helper<typename
+ remove_cv<_Tp>::type>::value)>
+ { };
/// is_reference
template<typename _Tp>
template<typename _Tp>
struct is_function;
- /// is_member_object_pointer
template<typename>
- 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<typename _Tp>
+ struct is_member_object_pointer
+ : public integral_constant<bool, (__is_member_object_pointer_helper<
+ typename remove_cv<_Tp>::type>::value)>
+ { };
+
template<typename>
- 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<typename _Tp>
+ struct is_member_function_pointer
+ : public integral_constant<bool, (__is_member_function_pointer_helper<
+ typename remove_cv<_Tp>::type>::value)>
+ { };
+
/// is_enum
template<typename _Tp>
struct is_enum
: public integral_constant<bool, __is_class(_Tp)>
{ };
- template<typename _Tp>
- struct remove_cv;
-
template<typename>
struct __is_function_helper
: public false_type { };
{ typedef typename remove_all_extents<_Tp>::type type; };
/// pointer modifications [4.7.4].
-#undef _DEFINE_SPEC_BODY
-#define _DEFINE_SPEC_BODY(_Value) \
+ template<typename _Tp, typename>
+ struct __remove_pointer_helper
{ typedef _Tp type; };
+ template<typename _Tp, typename _Up>
+ struct __remove_pointer_helper<_Tp, _Up*>
+ { typedef _Up type; };
+
/// remove_pointer
template<typename _Tp>
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<typename _Tp>
+ template<typename>
struct remove_reference;
/// add_pointer
#undef _DEFINE_SPEC_1_HELPER
#undef _DEFINE_SPEC_2_HELPER
#undef _DEFINE_SPEC
-#undef _DEFINE_SPEC_BODY
_GLIBCXX_END_NAMESPACE_TR1
}