[complement-svn] SF.net SVN: complement:[1967] trunk/complement/explore/include/misc/ type_traits.h
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-09-09 06:28:39
|
Revision: 1967 http://complement.svn.sourceforge.net/complement/?rev=1967&view=rev Author: complement Date: 2008-09-09 06:28:34 +0000 (Tue, 09 Sep 2008) Log Message: ----------- add make_signed/make_unsigned; replace add_reference by lvalue/rvalue Close to [http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2008/n2723.pdf] syntax. Modified Paths: -------------- trunk/complement/explore/include/misc/type_traits.h Modified: trunk/complement/explore/include/misc/type_traits.h =================================================================== --- trunk/complement/explore/include/misc/type_traits.h 2008-09-08 19:58:50 UTC (rev 1966) +++ trunk/complement/explore/include/misc/type_traits.h 2008-09-09 06:28:34 UTC (rev 1967) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/20 18:17:36 ptr> +// -*- C++ -*- Time-stamp: <08/09/09 10:22:13 ptr> /* * Copyright (c) 2007, 2008 @@ -6,6 +6,8 @@ * * Licensed under the Academic Free License version 3.0 * + * Should be close to JTC1/SC22/WG21 C++ 0x working draft + * [http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2008/n2723.pdf] */ #ifndef __misc_type_traits_h @@ -193,7 +195,7 @@ __SPEC_2(C,T volatile,B); \ __SPEC_2(C,T const volatile,B) -// [4.5.1] primary type categories: +// [20.5.4.1] primary type categories: template <class _Tp> struct is_void : @@ -352,8 +354,10 @@ public integral_constant<bool, (is_member_object_pointer<_Tp>::value || is_member_function_pointer<_Tp>::value)> { }; -// 4.5.2 composite type categories +// [20.5.4.2] composite type categories +// is_reference see above + template <class _Tp> struct is_arithmetic : public integral_constant<bool, (is_integral<_Tp>::value || is_floating_point<_Tp>::value)> @@ -364,7 +368,7 @@ public integral_constant<bool, (is_arithmetic<_Tp>::value || is_void<_Tp>::value)> { }; -// [4.5.1] primary type categories (continued): +// [20.5.4.1] primary type categories (continued): template <class _Tp> struct is_enum : @@ -387,7 +391,7 @@ // is_function (above) -// 4.5.2 composite type categories (continued) +// [20.5.4.2] composite type categories (continued) // is_arithmetic (above) // is_fundamental (above) @@ -416,7 +420,7 @@ // is_member_pointer -// 4.5.3 type properties: +// [20.5.4.3] type properties: template <class _Tp> struct is_const : @@ -439,7 +443,7 @@ { }; -// 4.7.3 array modifications: +// [20.5.6.4] array modifications: template <class _Tp> struct remove_extent @@ -477,7 +481,7 @@ typedef typename remove_all_extents<_Tp>::type type; }; -// 4.5.3 type properties (continued): +// [20.5.4.3] type properties (continued): template <class _Tp> struct is_trivial : @@ -507,12 +511,12 @@ // is_abstract template <class _Tp> -struct has_trivial_constructor : +struct has_trivial_default_constructor : public integral_constant<bool, is_pod<_Tp>::value> { }; template <class _Tp> -struct has_trivial_copy : +struct has_trivial_copy_constructor : public integral_constant<bool, is_pod<_Tp>::value> { }; @@ -527,12 +531,12 @@ { }; template <class _Tp> -struct has_nothrow_constructor : +struct has_nothrow_default_constructor : public integral_constant<bool, is_pod<_Tp>::value> { }; template <class _Tp> -struct has_nothrow_copy : +struct has_nothrow_copy_constructor : public integral_constant<bool, is_pod<_Tp>::value> { }; @@ -572,7 +576,7 @@ // rank // extent -// 4.6 type relations: +// [20.5.5] type relations: template <class _Tp1, class _Tp2> struct is_same : @@ -587,7 +591,7 @@ // is_base_of // is_convertible -// 4.7.1 const-volatile modifications +// [20.5.6.1] const-volatile modifications template <class _Tp> struct remove_const @@ -624,20 +628,32 @@ { typedef _Tp const type; }; - + template <class _Tp> +struct add_const<_Tp const> +{ + typedef _Tp const type; +}; + +template <class _Tp> struct add_volatile { typedef _Tp volatile type; }; template <class _Tp> +struct add_volatile<_Tp volatile> +{ + typedef _Tp volatile type; +}; + +template <class _Tp> struct add_cv { typedef typename add_const<typename add_volatile<_Tp>::type>::type type; }; -// 4.7.2 reference modifications: +// [20.5.6.2] reference modifications: template <class _Tp> struct remove_reference @@ -651,23 +667,185 @@ typedef _Tp type; }; +// template <class _Tp> +// struct remove_reference<_Tp&&> +// { +// typedef _Tp type; +// }; + template <class _Tp> -struct add_reference +struct add_lvalue_reference { typedef _Tp& type; }; template <class _Tp> -struct add_reference<_Tp&> +struct add_lvalue_reference<_Tp&> { typedef _Tp& type; }; + +// template <class _Tp> +// struct add_rvalue_reference +// { +// typedef _Tp&& type; +// }; -// 4.7.3 array modifications (see above) +// template <class _Tp> +// struct add_rvalue_reference<_Tp&&> +// { +// typedef _Tp&& type; +// }; -// 4.7.4 pointer modifications: +// [20.5.6.3] sign modifications template <class _Tp> +struct make_signed +{ +}; + +template <> +struct make_signed<char> +{ + typedef signed char type; +}; + +template <> +struct make_signed<signed char> +{ + typedef signed char type; +}; + +template <> +struct make_signed<unsigned char> +{ + typedef signed char type; +}; + +template <> +struct make_signed<short> +{ + typedef short type; +}; + +template <> +struct make_signed<unsigned short> +{ + typedef short type; +}; + +template <> +struct make_signed<int> +{ + typedef int type; +}; + +template <> +struct make_signed<unsigned int> +{ + typedef int type; +}; + +template <> +struct make_signed<long> +{ + typedef long type; +}; + +template <> +struct make_signed<unsigned long> +{ + typedef long type; +}; + +template <> +struct make_signed<long long> +{ + typedef long long type; +}; + +template <> +struct make_signed<unsigned long long> +{ + typedef long long type; +}; + +template <class _Tp> +struct make_unsigned +{ +}; + +template <> +struct make_unsigned<char> +{ + typedef unsigned char type; +}; + +template <> +struct make_unsigned<signed char> +{ + typedef unsigned char type; +}; + +template <> +struct make_unsigned<unsigned char> +{ + typedef unsigned char type; +}; + +template <> +struct make_unsigned<short> +{ + typedef unsigned short type; +}; + +template <> +struct make_unsigned<unsigned short> +{ + typedef unsigned short type; +}; + +template <> +struct make_unsigned<int> +{ + typedef unsigned int type; +}; + +template <> +struct make_unsigned<unsigned int> +{ + typedef unsigned int type; +}; + +template <> +struct make_unsigned<long> +{ + typedef unsigned long type; +}; + +template <> +struct make_unsigned<unsigned long> +{ + typedef unsigned long type; +}; + +template <> +struct make_unsigned<long long> +{ + typedef unsigned long long type; +}; + +template <> +struct make_unsigned<unsigned long long> +{ + typedef unsigned long long type; +}; + +// [20.5.6.4] array modifications (see above) + +// [20.5.6.5] pointer modifications: + +template <class _Tp> struct remove_pointer { typedef _Tp type; @@ -703,9 +881,10 @@ typedef typename remove_reference<_Tp>::type * type; }; -// 4.8 other transformations: +// [20.5.7] other transformations: -// aligned_storage +// template <std::size_t Len, std::size_t Align> struct aligned_storage; +// template <std::size_t Len, class... Types> struct aligned_union; namespace detail { @@ -768,6 +947,8 @@ typedef _Tp1 type; }; +// template <class... _Tp> struct common_type; + #undef __CV_SPEC #undef __SPEC_ #undef __CV_SPEC_1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |