fork(1) download
  1. #include <array>
  2.  
  3. // globally:
  4. template<typename T>
  5. using enum_traits = decltype(get_enum_traits(T{}));
  6.  
  7. // inside the macro:
  8. #define DEFINE_ENUM(Name, ...) \
  9.   /* define "enum class Name" ... */ \
  10.   enum class Name { __VA_ARGS__ }; \
  11.   struct Name##_type_traits { \
  12.   static constexpr std::array<Name,1> values{{ Name{} }}; \
  13.   }; \
  14.   Name##_type_traits get_enum_traits(Name); // does not need implementation
  15.  
  16.  
  17. namespace foo {
  18. DEFINE_ENUM(Foo, Value1, Value2);
  19. }
  20.  
  21. int main( ) {
  22. for (auto e: enum_traits<foo::Foo>::values)
  23. {}
  24. }
  25.  
Success #stdin #stdout 0s 4588KB
stdin
Standard input is empty
stdout
Standard output is empty