-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reflect an existing enum? #76
Comments
No, not at the moment. You can define a new reflective enum with BETTER_ENUM(Foo, int, A = OtherEnum::A, B = OtherEnum::B) and use this second enum for conversions of values of |
Ok, thanks; any plans to add this feature? :-) Perhaps you could reuse essentially the same large macro to define it, but instead of creating an actual enum inside of it, you can just instead have a
you could have:
But of course I could be wrong since I am not too familiar with this code, |
It's feasible at first glance, but I wouldn't have time in the near future to do this, test it everywhere, etc. If you would like to give it a try, I would be happy to merge the PR. If you make something like this locally, but don't want to test it on all the systems and configurations and whatnot, I'd also be very happy if you opened a PR with your approach. We would close and not merge it, but it would give us a nice starting point if I/someone else wanted to finish it "all the way" later :) |
Ok, I will take a look and try to put together a PR. For testing I will follow the directions in |
To have reflecting an existing enum you can use https://github.com/Neargye/magic_enum for example. |
I linked magic_enum from the README. It looks like it requires GCC 9, but otherwise, is likely to be a better solution for many situations. If so, I'd like to gradually deprecate Better Enums. cc @Neargye |
Hi @aantron, Both libraries solve similar problems, but with a different implementation. Difference: Better Enums
Magic Enums
|
Cool! I will give magic_enum a try; I suppose that it might be able to replace most uses of Better Enums in my code. But of course it is not the right solution for everyone due to the requirements on compilers and compiler versions (i.e., parsing PRETTY_FUNCTION is compiler specific). |
@dpacbach Unfortunately, "magic" depends on the compiler :D |
@Neargye thanks. "Perversely," on MSVC, magic_enum might actually have less of a limit than Better Enums. Better Enums uses macro expansion, which is (or was?) limited to 127 arguments on MSVC. I think the main genuine advantage of Better Enums is that it can easily handle large sparse ranges, and constants with arbitrary values, whereas magic_enum seems to "like" dense, contiguous, narrow ranges. Most enums fall into that latter category, though, so magic_enum is probably the better solution for most uses. This should become more and more true as GCC 9 becomes more common, and future versions are released. |
Well, and that Better Enums uses standard C++. But I think the vast majority of users are on GCC, Clang, or MSVC, so this is not a big deal. |
Does this library have a macro for reflecting an existing
enum class
(which is not reflected in any way)? I understand that this would require restating the enum values, but that's ok. Essentially, this would be for a case where we need to reflect an enum but cannot change the original declaration.The text was updated successfully, but these errors were encountered: