C++03中C++枚举的基础类型
Underlying type of a C++ enum in C++03
有没有办法在C++03编译器中获得std::underlying_type的等效值?
我知道boost::type_traits中有一些支持,但那里没有功能齐全的转换器。
这个解决方案怎么样?
template< class TpEnum >
struct UnderlyingType
{
typedef typename conditional<
TpEnum( -1 ) < TpEnum( 0 ),
typename make_signed< TpEnum >::type,
typename make_unsigned< TpEnum >::type
>::type type;
};
您可以找到它的构建块(conditional,make_signed,make_unsigned in boost::type_traits)
相关文章:
- 在有符号基础类型枚举的位域上溢出
- 在编译时将强类型枚举器转换为其基础类型?
- 如果 int 是"not within the enums range",为什么将 int 转换为强类型枚举会编译?
- 类型枚举的变量不是类型名称
- 强类型枚举的语法实现错误
- 枚举与强类型枚举
- 错误:T没有命名类型-用于使用强类型枚举的专门化
- 如何使用强类型枚举
- QT:将强类型枚举参数传递到插槽
- 在类定义中声明类型(枚举、结构等)会增加代码大小
- Visual Studio 11 (beta) 中的强类型枚举类
- 使用强类型枚举对类型和子类型进行建模
- 不允许将强类型枚举用作同一基础类型的参数
- 如何正确使用C++强类型枚举
- 带有强类型枚举的模板参数推导
- 是否可以在googleprotobuf中为类型(枚举或消息)定义一个别名
- C++中默认初始化的全局强类型枚举是什么
- std::is_signed不适用于强类型枚举:int
- 如何定义自定义值的类型?(枚举类型定义)
- 将强类型枚举传递给函数