stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: type_traits is_integral implementation
Date Wed, 27 Dec 2006 18:28:04 GMT
Martin Sebor wrote:
> Scott Zhong wrote:
> 
>> I try to implement type_traits using partial specialization as follows:
[...]
 > The goal should be to come up with an elegant,
> compact implementation that's fast to compile and that generates
> the least number of specializations of implementation classes
> (deep template recursion is the enemy of compile time efficiency).
[...]
> // __is_std_signed specializations for each standard signed
> // integer type (T must not be cv-qualified)
> template <> struct __is_std_signed<signed char>: true_type { };

FWIW, changing this and the rest of the __is_std_xxx helpers to

   template <>
   struct __is_std_signed<const volatile signed char>
       : true_type { };

and the is_signed, is_unsigned, and is_integral traits to avoid
using remove_cv by adding const volatile as shown below reduced
gcc 4.1 compilation time of the test program by 10%.

[...]
> template <class T>
> struct is_signed:
>   integral_constant<bool,
>                        __is_std_signed<typename remove_cv<T>::type>::value
>                     || __is_ext_signed<typename remove_cv<T>::type>::value>
> { };


     template <class T>
     struct is_signed
         : integral_constant<bool,
                  __is_std_signed<const volatile T>::value
               || __is_ext_signed<const volatile T>::value> >
     { };

and

> template <class T>
> struct is_integral:
>   integral_constant<
>     bool,
>        is_signed<T>::value
>     || is_unsigned<T>::value
>     || is_same<typename remove_cv<T>::type, bool>::value
>     || is_same<typename remove_cv<T>::type, char>::value
>     || is_same<typename remove_cv<T>::type, wchar_t>::value>
> { };

     template <class T>
     struct is_integral:
     integral_constant<
         bool,
            is_signed<T>::value
         || is_unsigned<T>::value
         || is_same<const volatile T, const volatile bool>::value
         || is_same<const volatile T, const volatile char>::value
         || is_same<const volatile T, const volatile wchar_t>::value> >
     { };

Martin

Mime
View raw message