Suppose I need to make a template with a member of exactly N
bits in length, where N
is the template parameter. I could of course define something like this
#include <cstdint>
template<int N>
struct sized_uint {};
template<> struct sized_uint<8> { typedef uint8_t type; };
template<> struct sized_uint<16> { typedef uint16_t type; };
template<> struct sized_uint<32> { typedef uint32_t type; };
template<> struct sized_uint<64> { typedef uint64_t type; };
and then use it in my template for e.g. a function:
template<int N> void myfunc(typename sized_uint<N>::type);
But are there any standard types like the above defined sized_uint
in any version of C++?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…