如何获得枚举的基本类型?
问题描述:
带有如下声明:
enum DrawBoldMode : unsigned
{
DBM_NONE = 0,
DBM_ITEM = 1<<0, // bold just the nearest line
DBM_SECTION = 1<<1, // bold all lines in the same section
DBM_LINETYPE = 1<<2, // bold all lines of the same line type
DBM_POINTAGE = 1<<3, // bold all lines of the same line type
};
如何获取DrawBoldMode的基础类型(即未签名)?
How can I derive the underlying type of DrawBoldMode (i.e. unsigned)?
答
它应该以 std :: underlying_type< DrawBoldMode> :: type
的形式提供。但是,我的编译器(GCC 4.6.1)似乎并未实现。
It should be available as std::underlying_type<DrawBoldMode>::type
. However, my compiler (GCC 4.6.1) doesn't seem to implement that.
我认为不可能用模板来实现,但是我对此可能是错的。
I think it's impossible to implement it with templates, but I could be wrong about that.