Open utterances-bot opened 1 month ago
If you want to convert enum into strings and you don't want to wait for C++26, you can have a look at magic_enum header only library, which provides this functionality (and many others).
Hi, thanks for the article. I do not usually do C++ but I like to know how the language is evolving.
I have two very minor typos for you to consider.
In the permissions example, we conventionally use Read=4, Write=2, Execute=1. Your example flips read and execute conventional values. It doesn't matter to the discussion but since it slightly distracted me it may distract others (or maybe I am just too easily distracted!).
Also there is a typo at CompueEngine (a "t" is missing)
Thanks again.
Possibly annoying note: I'd refrain from using bare C functions and types in C++ (like uint8_t and the like), AFAIK you're not guaranteed to have them in the global namespace.
Thanks for the comments! @zeehio - I updated the text, thanks! @maxpagani - I added a note about magic enum @mcilloni - you're right, but let's leave that in examples for simplicity
Another option for C++20 is conjure_enum
Enum class improvements for C++17, C++20 and C++23 - C++ Stories
The evolution of the C++ language continues to bring powerful features that enhance code safety, readability, and maintainability. Among these improvements, we got changes and additions to enum class functionalities across C++17, C++20, and C++23. In this blog post, we’ll explore these advancements, focusing on initialization improvements in C++17, the introduction of the using enum keyword in C++20, and the std::to_underlying utility in C++23.
https://www.cppstories.com/2024/enum-improvements/