c++ - C++03 中 C++ 枚举的底层类型

标签 c++ std typetraits

有没有办法在 C++03 编译器中获得 std::underlying_type 的等价物?

我知道 boost::type_traits 中有一些支持,但那里没有功能齐全的转换器。

最佳答案

this怎么样?解决方案?

template< class TpEnum >
struct UnderlyingType
{
    typedef typename conditional<
        TpEnum( -1 ) < TpEnum( 0 ),
        typename make_signed< TpEnum >::type,
        typename make_unsigned< TpEnum >::type
        >::type type;
};

您可以找到它的构建 block (在 boost::type_traits 中有条件、make_signed、make_unsigned)

关于c++ - C++03 中 C++ 枚举的底层类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26148192/

相关文章:

C++ 模板特化 - 避免重新定义

c++ - 如何根据模板类型的祖先限制类的实例化

c++ - 如何定义 is_iterator 类型特征?

c++ - 从 (long)double 转换为 size_t

c++ - std::addressof - 奇怪的实现

C++ 入门第 5 版函数模板特化

c++ - 根据另一个 vector 中的元素过滤/复制一个 vector

c++ - cppreference的编码样式在哪里定义?

C++ 数学问题和 5/4*pi 与 5*pi/4

c++ - 我可以访问地址零吗?