|
Boost : |
From: vesa_karvonen (vesa_karvonen_at_[hidden])
Date: 2002-02-22 03:16:33
--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> There are a number of type properties like is_POD which should
> probably be propagated through arrays and cv-qualifications:
I would personally try to avoid specializing traits for each T, T c,
T v and T cv. I would specialize only for T cv and use the type
transformation traits to add cv qualifications. I'm not worried about
compilers whose template recursion depth is small by default. Those
compiler will be fixed or already have an option to increase the
depth.
template<class t>
struct is_integral
{ enum
{ value =
is_integral_cv
< typename add_volatile
< typename add_const<t>::type
>::type
>::value
};
};
// This could also be put into the detail namespace
template<class T>
struct is_integral_cv
{ enum { value = false }; };
#define INTEGRAL_TYPES\
BOOST_PP_TUPLE_TO_LIST\
( 9\
, ( char\
, signed char\
, unsigned char\
, short\
, unsigned short\
, int\
, unsigned\
, long\
, unsigned long\
)\
)
#define IS_INTEGRAL_CV_SPECIALIZATION(R,_,T)\
template<>\
struct is_integral_cv<T const volatile>\
{enum {value = true};};
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_CV_SPECIALIZATION,_,INTEGRAL_TYPES)
#undef IS_INTEGRAL_CV_SPECIALIZATION
#undef INTEGRAL_TYPES
Even after adding the standard wchar_t and other non-standard
integral types, this would be much much shorter than the current
is_integral implementation.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk