3 ms·
There are also other approaches. Macro variants making use of `__VA_ARGS__` would be probably the best trade-off. If you want a slightly more ergonomic syntax,
by lifthrasiir 3y ago
There are also other approaches. Macro variants making use of `__VA_ARGS__` would be probably the best trade-off. If you want a slightly more ergonomic syntax, something like Metalang99 [1] will help (and the author even wrote a post about this exact subject [2]). Codegen is another option which may work better than other options depending on the situation and exact implementation strategy. And there is always the Reflection TS [3], which may or may not be incorporated to C++26...
[1] https://github.com/Hirrolot/metalang99 https://github.com/Hirrolot/metalang99
[2] https://hirrolot.github.io/posts/pretty-printable-enumerations-in-pure-c.html https://hirrolot.github.io/posts/pretty-printable-enumeratio...
[3] https://en.cppreference.com/w/cpp/experimental/reflect https://en.cppreference.com/w/cpp/experimental/reflect
- gpderetta 3y agoAn interface like DEF_ENUM( EnumName, (Name1, value1) (Name2, value2) ...); Is also possible. I'm not the greatest fan of PP metaprogramming, but I think this is acceptable. With additional Magic it might be possible to do separate compilation of the to_string() function.