Boost logo

Boost Users :

From: Slawomir Lisznianski (slisznianski_at_[hidden])
Date: 2005-07-23 21:09:27


Howard Hinnant wrote:
> template <class T> struct to_unsigned_integral
> {typedef T type;};
> template <> struct to_unsigned_integral<char>
> {typedef unsigned char type;};
> template <> struct to_unsigned_integral<signed char>
> {typedef unsigned char type;};
> template <> struct to_unsigned_integral<short>
> {typedef unsigned short type;};
> template <> struct to_unsigned_integral<int>
> {typedef unsigned int type;};
> template <> struct to_unsigned_integral<long>
> {typedef unsigned long type;};
> #if YOUVE_GOT_IT
> template <> struct to_unsigned_integral<long long>
> {typedef unsigned long long type;};
> #endif

Hey, thanks! I thought I was reinventing the wheel when I came up with a
similar implementation. Maybe I was just being naive, but I hoped that
the Boost Numeric Conversion Library would be of some help here, no?

> If you're paranoid about non-integral types you could dress up the
> primary template a little to return T only for integral types,

Indeed, I'm doing it with the combination of enable_if and is_integral.

> -Howard

Thanks a lot!
Slawomir


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net