Is there any way in C++ define a type that is big enough to hold at most a specific number, presumably using some clever template code. For example I want to be able to writ
#define UINT8_T 256
#define UINT16_T 65536
#define UINT32_T 4294967296
template
struct UInt16_t { typedef uint16_t type; };
template
struct UInt16_t { typedef uint32_t type; };
template
struct UInt8_t { typedef uint8_t type; };
template
struct UInt8_t { typedef typename UInt16_t::type type; };
template
struct Integer {
typedef typename UInt8_t::type type;
};
You can extend upto uint64_t or whatever your platform supports.
Demo.