[prev in list] [next in list] [prev in thread] [next in thread]
List: apache-stdcxx-dev
Subject: Re: type_traits is_integral implementation
From: Martin Sebor <sebor () roguewave ! com>
Date: 2006-12-27 18:28:04
Message-ID: 4592BB34.2030505 () roguewave ! com
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic