C ++ 03中C ++枚举的基础类型

时间:2014-10-01 18:34:42

标签: c++ std typetraits

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

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

1 个答案:

答案 0 :(得分:2)

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;
};

你可以找到它的构建块(在boost :: type_traits中有条件,make_signed,make_unsigned)