Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-02-22 08:30:49


It's a nice approach, but you have to be careful about how it's applied.
Suppose I specialize is_POD<my_struct>::value == true. Will
has_trivial_destructor<T>::value be true? I wouldn't like the answer if it
were "it depends on the implementation".

-Dave

----- Original Message -----
From: "vesa_karvonen" <vesa_karvonen_at_[hidden]>

> 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