C++ 是否存在大小为模板参数的标准整数类型?

C++ 是否存在大小为模板参数的标准整数类型?,c++,templates,integer,C++,Templates,Integer,假设我需要创建一个模板,其成员长度正好为N位,其中N是模板参数。我当然可以这样定义 #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

假设我需要创建一个模板,其成员长度正好为
N
位,其中
N
是模板参数。我当然可以这样定义

#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; };
#包括
模板
结构大小的单元{};
模板结构大小_uint{typedef uint8_t type;};
模板结构大小_uint{typedef uint16_t type;};
模板结构大小_uint{typedef uint32_t type;};
模板结构大小为{typedef uint64\u t type;};
然后在我的模板中使用它,例如函数:

template<int N> void myfunc(typename sized_uint<N>::type);
模板void myfunc(typename size\u uint::type);

< C++ >

中没有任何标准类型,如上面定义的<代码> siZeDuuuu>/Cuth>,没有标准类型。但是,如果boost依赖性对您来说是可以接受的,那么它将满足您的需求。请注意,语义稍有不同,因为
boost::int_t
将为您提供至少有那么多位的最小整数类型,而不是正好有那么多位。

看看这个,我的回答相当出色;=)。你可以用类似的方法来处理这个问题。2016年的日期和它引用的Boost.Integer,[P0381R1]()支持这个答案的正确性。不过,我想使用这种类型的两件事可以在
中找到:。