| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Single-header facility for compile time reflection of enums in C++17.
See compiled code at: https://godbolt.org/z/TaPqPa
Either make sure the meta_enum.hpp file is made available in your include paths or just copy it to your project.
#include <meta_enum.hpp>Use the macro meta_enum to declare your enums.
meta_enum(Days, int, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
//equivalent to:
//enum Days : int { Monday, ...Or use meta_enum_class for enum class.
The meta_enum macro supports assigning custom values to entries as per usual.
meta_enum(MyEnum, uint8_t, First = 0, Second = 1 << 5, Third = myConstexprFunction<int>());By using meta_enum to declare MyEnum, you get the global constexpr object MyEnum_meta which stores a representation of your enum and is of type MetaEnum.
Typedefs:
Members:
Members:
A few functions are provided per meta_enum to ease usage.
For an enum with the name MyEnum you will get the following:
See the file in the repo examples.cpp
Some configurations of certain compilers seem to break down when building this. Specifically there is a problem with clang 6.0 on godbolt which fails to build due to what looks like problems with std::string_view not being constexpr even though it should be. See: https://godbolt.org/z/Ob9Cnv There has also been problems when building with the MSVC Pre 2018 hosted @godbolt.org as well when it builds with the complex test case inside of example.cpp. It works however for the typical case. See: https://godbolt.org/z/rIhpfR
meta_enum uses string parsing to be able to extract the names of each enum entry. This string parsing takes into account that enum declarations can contain pretty complex meta-programming expressions - it's not as simple as counting commas. The algorithm for doing so is somewhat naive and cannot tell apart >> as the operator and >> as the end of two nested templates (std::vector<std::vector<int>> for example). Due to this, nested template angle brackets have to be separated by whitespace, i.e. >> has to be > >.
I'm gladly welcoming suggestions for improvements, pull requests, bug reports, comments or whatever. :)
| Back | FazBrowse Home | New Git URL |