|
Boost : |
Subject: Re: [boost] unsigned long vs unsigned int vs std::size_t (32b platform)
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-20 18:59:03
AMDG
Christoph Mathys wrote:
>> Wouldn't a template function be appropriate here?
>
> Maybe a template function would be more appropriate, avoiding possibly
> dangerous conversions by putting a static assert into the default
> implementation. But I'd still have to provide specializations for
> uint32_t and unsigned long or uint32_t and unsigned int, depending on
> the platform.
>
> Ideally, I'd like to work only with those fixed width integers if I
> need to provide an implementation for every integer type, avoiding
> code noise with ifdef and co.
Would it make sense to dispatch on the size:
#include <climits>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/int.hpp>
template<class T>
struct bits : boost::mpl::int_<sizeof(T) * CHAR_BIT> {};
template<class T>
void someFunc(T, boost::mpl::int_<64>) {}
template<class T>
void someFunc(T, boost::mpl::int_<32>) {}
template<class T>
void someFunc(T, boost::mpl::int_<16>) {}
template<class T>
void someFunc(const T& t) {
return(someFunc(t, bits<T>()));
}
int main() {
someFunc(1);
}
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk