fork(1) download
  1. #include <type_traits>
  2.  
  3. template <typename E>
  4. typename std::underlying_type<E>::type to_underlying(E e) {
  5. return static_cast<typename std::underlying_type<E>::type>(e);
  6. }
  7.  
  8. using uint = unsigned;
  9. //enum class foo : unsigned { bar }; // works
  10. enum class foo : uint { bar }; // fails
  11.  
  12. void f(unsigned) {}
  13.  
  14. int main() {
  15. f(to_underlying(foo::bar));
  16. f(static_cast<std::underlying_type<foo>::type>(foo::bar));
  17. }
  18.  
  19.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty