Reputation: 20058
Is there a way to get the equivalent of std::underlying_type in C++03 compilers?
I'm aware of some support in boost::type_traits, but there is no fully functional converter there.
Upvotes: 0
Views: 440
Reputation: 73366
How about this solution?
template< class TpEnum >
struct UnderlyingType
{
typedef typename conditional<
TpEnum( -1 ) < TpEnum( 0 ),
typename make_signed< TpEnum >::type,
typename make_unsigned< TpEnum >::type
>::type type;
};
You can find the building blocks for it (conditional, make_signed, make_unsigned in boost::type_traits)
Upvotes: 2