[cfe-dev] Why is compiler support needed for std::underlying_type?

Stephen Kelly steveire at gmail.com
Mon Oct 21 12:30:15 PDT 2013


Richard Smith wrote:

> enum E1 : long {};
> static_assert(std::is_same<std::underlying_type<E>::type, long>::value,
> ""); // ok
> static_assert(std::is_same<UnderLyingType<E>::Type, long>::value, ""); //
> fails
> 
> enum E2 : char {};
> static_assert(std::is_same<std::underlying_type<E>::type, char>::value,
> ""); // ok
> static_assert(std::is_same<UnderLyingType<E>::Type, char>::value, ""); //
> fails
> 

Am I right to say this? :

Even if sizeof(long)==sizeof(long long), they are not the same type. The 
compiler intrinsic knows that, but my solution does not.

Similarly, signed char, char and unsigned char are three different distinct 
types. The compiler knows this, but my solution does not.

Thanks,

Steve.





More information about the cfe-dev mailing list