1
#define enumDEF(ename,...) enum ename{__VA_ARGS__}; \
    const int _int_##ename []={__VA_ARGS__};\
    char _str_##ename[]={ #__VA_ARGS__ };\
    int _cnt_##ename =sizeof(_int_##ename)/sizeof(int);
 
    enumDEF(DAYS, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)

 DAYS nnn = Monday;
 int count = _cnt_DAYS;

Count is ok. But: _str_DAYS="Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"

I need, all item by array. Like this _str_DAYS[0]="Monday" _str_DAYS[1]="Tuesday"

_str_DAYS[6]="Sunday"

Possible?

BuhX
  • 11
  • 2
  • See for example [this](https://stackoverflow.com/q/11920577/3740047) or [this](https://stackoverflow.com/q/44479282/3740047) post. – Sedenion Sep 02 '22 at 19:02
  • thx. but- I don't want such a solution. I don't like that I have to enter every variation, the number of parameters. In 1984, the MASM compiler already knew this well. :-) – BuhX Sep 05 '22 at 05:00
  • Well, you could also use existing libraries. E.g. [magic enum](https://github.com/Neargye/magic_enum), which apparently does not require any boilerplate code. Otherwise, also check the list [here](https://github.com/fffaraz/awesome-cpp#reflection). – Sedenion Sep 05 '22 at 05:28

0 Answers0