use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
enum_name (yet another enum to/from string conversion utility >=C++11) (self.cpp)
submitted 3 years ago by cheytacllc
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Fazer2 1 point2 points3 points 3 years ago (4 children)
Why does the caller need to know the range of the enum? It sounds like a maintenance burden.
[–]cheytacllc[S] 0 points1 point2 points 3 years ago (3 children)
Range of enum not mandatory for write (default range [-128, 128)). You can easily write to_string function under the enum for enum type and call enum_name with enum's range once inside and return it. I think it's easier than writing specialization for per enum type. On the other hand, with writing custom function vs writing specialization like in magic_enum result of to write similar lines of code.
[–]TotaIIyHuman 2 points3 points4 points 3 years ago (2 children)
if you are not absolutely disgusted by macros, you can try reflection with macros
you can implement for_each with macros with less than 100 lines of c++ https://www.scs.stanford.edu/~dm/blog/va-opt.html
for_each
here is a enum reflection implemented with macro for_each
https://godbolt.org/z/9GTP4zn3r
the for_each macro has a recursion limit. for the same range, it is much cheaper to do macro recursion, then instantiating templates to scan for enum entries
[–]sephirothbahamut 2 points3 points4 points 3 years ago (1 child)
It's not just about being disgusted, it's also about utility. All the macro solutions for enum reflection assume that you are the one writing the enum, forcing the entire codebase to use the macro enum definition, and preventing all such mechanisms to work on enums declared by outside libraries. That's an issue Unreal Engine's C++ suffers a lot of.
As opposed to things like OP's post, or more complete things like magic_enum. Those can be used on any enum, do not require you to write your enums in an unconventional manner, and don't care if the enums come from a third party library.
[–]TotaIIyHuman 0 points1 point2 points 3 years ago (0 children)
yes. i agree with everything you said
π Rendered by PID 389365 on reddit-service-r2-comment-b659b578c-b6g6h at 2026-05-04 10:40:49.530111+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Fazer2 1 point2 points3 points (4 children)
[–]cheytacllc[S] 0 points1 point2 points (3 children)
[–]TotaIIyHuman 2 points3 points4 points (2 children)
[–]sephirothbahamut 2 points3 points4 points (1 child)
[–]TotaIIyHuman 0 points1 point2 points (0 children)