#include <iostream> #include <type_traits> enum e1 {}; enum class e2 {}; enum class e3: unsigned {}; enum class e4: int {}; int main() { constexpr bool e1_t = std::is_same< std::underlying_type<e1>::type, int >::value; constexpr bool e2_t = std::is_same< std::underlying_type<e2>::type, int >::value; constexpr bool e3_t = std::is_same< std::underlying_type<e3>::type, int >::value; constexpr bool e4_t = std::is_same< std::underlying_type<e4>::type, int >::value; std::cout << "underlying type for 'e1' is " << (e1_t ? "int" : "non-int") << '\n' << "underlying type for 'e2' is " << (e2_t ? "int" : "non-int") << '\n' << "underlying type for 'e3' is " << (e3_t ? "int" : "non-int") << '\n' << "underlying type for 'e4' is " << (e4_t ? "int" : "non-int") << '\n' ; }
underlying_type
最新推荐文章于 2024-04-15 20:08:10 发布