|
Boost : |
Subject: Re: [boost] Bits and Ints: Intention Request
From: Murilo Adriano Vasconcelos (muriloufg_at_[hidden])
Date: 2010-07-14 20:08:23
Hi,
2010/7/14 vicente.botet <vicente.botet_at_[hidden]>
> Murillo, please don't top post.
> ----- Original Message -----
> From: "Murilo Adriano Vasconcelos" <muriloufg_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Wednesday, July 14, 2010 10:43 PM
> Subject: Re: [boost] Bits and Ints: Intention Request
>
>
> >
> > But maybe it can be a good point to use enable_if<> to for 8 and 16-bit
> > integrals specializations and use the correct __builtin for the others
> like:
> >
> > template <typename T>
> > inline int count_leading_zeros(T value)
> > {
> > #ifndef BOOST_HAS_NO_INT64_T
> > return __builtin_clzll(value) - (64 - (sizeof(T) << 3));
> > #else
> > return __builtin_clz(value) - (32 - (sizeof(T) << 3));
> > #endif
> > }
>
> I gess the above code should be replace by the following one, when GNUC is
> defined, isn't it?
> > template<>
> > inline int count_leading_zeros(unsigned int value)
> > {
> > return __builtin_clz(value);
> > }
> >
> > template<>
> > inline int count_leading_zeros(unsigned long int value)
> > {
> > return __builtin_clzl(value);
> > }
> >
> > template<>
> > inline int count_leading_zeros(unsigned long long int value)
> > {
> > return __builtin_clzll(value);
> > }
> >
> > What do you think?
>
> Instead of function template specialization you can just use overloading.
> So the you can remove the 'template<>'
>
If `value` don't matches exacly with the parameter type (for example
uint8_t or uint16_t) we will receive one error because calling
`count_leading_zeros` with this parameter type is ambiguous.
So we can do something like this:
https://svn.boost.org/trac/boost/browser/sandbox/SOC/2010/bits_and_ints/boost/integer/count_leading_zeros.hpp?rev=64028(lines
32 to 51)
Or create overloads for uint8_t and uint16_t.
inline int count_leading_zeros(uint8_t value);
inline int count_leading_zeros(uint16_t value);
>
> Best,
> Vicente
>
>
>
Best,
-- Murilo Adriano Vasconcelos http://murilo.wordpress.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk