namespace GenericInts { enum TypeMapperTypeEnum { char_t, short_t, int_t, long_t, uchar_t, ushort_t, uint_t, ulong_t, notavailable_t }; //need a macro here because C++ does not allow a function call to be used as template instantiation parameter #define SizeToTypeMapper_gettype(size) (\ (size)==8*sizeof(signed char) ? GenericInts::char_t: \ (size)==8*sizeof(signed short)? GenericInts::short_t: \ (size)==8*sizeof(signed int) ? GenericInts::int_t: \ (size)==8*sizeof(signed long) ? GenericInts::long_t: \ GenericInts::notavailable_t ) template struct TypeMapper; // // the following template specialisations map from the type enum to the concrete type // template<> struct TypeMapper { typedef signed char type;}; template<> struct TypeMapper { typedef signed short type;}; template<> struct TypeMapper { typedef signed int type;}; template<> struct TypeMapper { typedef signed long type;}; template<> struct TypeMapper { typedef unsigned char type;}; template<> struct TypeMapper { typedef unsigned short type;}; template<> struct TypeMapper { typedef unsigned int type;}; template<> struct TypeMapper { typedef unsigned long type;}; template struct Int { typedef typename TypeMapper< SizeToTypeMapper_gettype(size) >::type signedtype; typedef typename TypeMapper< (GenericInts::TypeMapperTypeEnum) (SizeToTypeMapper_gettype(size) + (GenericInts::uchar_t - GenericInts::char_t)) >::type unsignedtype; }; }