// TR1 type_traits -*- C++ -*-
-// Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009 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
{
_GLIBCXX_BEGIN_NAMESPACE_TR1
+ /**
+ * @defgroup metaprogramming Type Traits
+ * @ingroup utilities
+ *
+ * Compile time type transformation and information.
+ * @{
+ */
+
// For use in __is_convertible_simple.
struct __sfinae_types
{
typedef struct { char __arr[2]; } __two;
};
-#define _DEFINE_SPEC_BODY(_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(_Order, _Trait, _Type, _Value) \
+ _DEFINE_SPEC_##_Order##_HELPER \
+ struct _Trait<_Type> \
: public integral_constant<bool, _Value> { };
-#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)
-
- /// helper classes [4.3].
+ // helper classes [4.3].
+
+ /// integral_constant
template<typename _Tp, _Tp __v>
struct integral_constant
{
/// 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].
+ /// remove_cv
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].
+
+ /// is_void
+ 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 { };
remove_cv<_Tp>::type>::value)>
{ };
- /// composite type traits [4.5.2].
+ // composite type traits [4.5.2].
+
+ /// is_arithmetic
template<typename _Tp>
struct is_arithmetic
: public integral_constant<bool, (is_integral<_Tp>::value
|| is_member_function_pointer<_Tp>::value)>
{ };
- /// type properties [4.5.3].
+ // type properties [4.5.3].
+ /// is_const
template<typename>
struct is_const
: public false_type { };
- /// is_const
template<typename _Tp>
struct is_const<_Tp const>
: public true_type { };
_Uint - 1>::value>
{ };
- /// relationships between types [4.6].
+ // relationships between types [4.6].
+
+ /// is_same
template<typename, typename>
struct is_same
: public false_type { };
struct is_same<_Tp, _Tp>
: public true_type { };
- /// const-volatile modifications [4.7.1].
+ // const-volatile modifications [4.7.1].
+
+ /// remove_const
template<typename _Tp>
struct remove_const
{ typedef _Tp type; };
add_const<typename add_volatile<_Tp>::type>::type type;
};
- /// array modifications [4.7.3].
+ // array modifications [4.7.3].
+
+ /// remove_extent
template<typename _Tp>
struct remove_extent
{ typedef _Tp type; };
struct remove_all_extents<_Tp[]>
{ typedef typename remove_all_extents<_Tp>::type type; };
- /// pointer modifications [4.7.4].
-#undef _DEFINE_SPEC_BODY
-#define _DEFINE_SPEC_BODY(_Value) \
+ // pointer modifications [4.7.4].
+
+ 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
+ // @} group metaprogramming
_GLIBCXX_END_NAMESPACE_TR1
}