6 ms·
Seems that it could be used to solve an old-time classic: generate a mapping from an enum value to its string representation. Another use case that comes to my
by bialpio 5y ago
Seems that it could be used to solve an old-time classic: generate a mapping from an enum value to its string representation. Another use case that comes to my mind is maybe automating test case generation. Occasionally I was running into situations where I thought code generation could be useful, but not sure what could be a "killer app" equivalent for this feature.
Related topic: standardizing reflection in c++.
https://youtu.be/ARxj3dfF_h0 https://youtu.be/ARxj3dfF_h0
https://en.cppreference.com/w/cpp/keyword/reflexpr https://en.cppreference.com/w/cpp/keyword/reflexpr
- ggrrhh_ta 5y agothat would be great :-)
- seanbax 5y agoEnum to string is a one-line expression in Circle: https://godbolt.org/z/93f5o77zv https://godbolt.org/z/93f5o77zv Circle has dozens of special traits for accessing useful stuff about types, packs, etc. Don't need to overengineer such a simple thing.
- malkia 5y agoThere is also this approach - https://github.com/Neargye/magic_enum https://github.com/Neargye/magic_enum the trick (relyiong __FUNCTION__ like macros/(funcs?)) is here - https://github.com/Neargye/magic_enum/blob/master/include/magic_enum.hpp#L327 https://github.com/Neargye/magic_enum/blob/master/include/ma... and https://github.com/Neargye/magic_enum/blob/master/include/magic_enum.hpp#L351 https://github.com/Neargye/magic_enum/blob/master/include/ma...
- pisssip 5y agoWhat’s wrong with an array