Boost logo

Boost :

Subject: Re: [boost] unsigned long vs unsigned int vs std::size_t (32bplatform)
From: Bo Persson (bop_at_[hidden])
Date: 2009-09-20 17:52:22


Christoph Mathys wrote:
> Thomas Suckow wrote:
>> Christoph Mathys wrote:
>>> void someFunc(boost::uint16_t) { }
>>> void someFunc(boost::uint32_t) { }
>>> void someFunc(std::size_t) { }
>>>
>>>
>> Not sure if you are optimizing for 16bit and 32bit.
>
> It is actually code handling some endianness stuff.
>
>> 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.
>

For sure, the typedefs must be an alias for some of the built in
types, so you would have to provide overloads for them - unsigned
short, unsigned int, unsigned long, and (in the very near future)
unsigned long long.

Bo Persson


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk