Creating enum class members with a macro

I want to create an enumeration with 255 elements as follows:

enum class MyEnum { Item0, Item1, //.... Item254, Item255 }; 

Is there a way to generate enumeration elements with a macro, rather than enumerate them at all?

+1
source share
2 answers

Well, it looks like OP is after BOOST_PP_ENUM_PARAMS . I will not say that this is the best solution, but it works for an enumeration with values ​​such as:

 enum class MyEnum { BOOST_PP_ENUM_PARAMS(256, Item) }; 
+3
source

you can use shell script to generate them ... i think they won't change often

 echo Item{0..255}, 
+2
source

Source: https://habr.com/ru/post/1011809/


All Articles