Add enum reflection #824
Replies: 7 comments
-
As a note, many cases may want the enum serialized as integers. Supporting that is worthwhile. |
Beta Was this translation helpful? Give feedback.
-
I agree, the default behavior should still be integers. I think reflection should happen if a enum class Color { Red, Green, Blue };
template <>
struct glz::meta<Color> {}; // This definition should trigger enum reflection |
Beta Was this translation helpful? Give feedback.
-
What are your thoughts on making it such that Then, as usual, the standard |
Beta Was this translation helpful? Give feedback.
-
Yeah, I think this is probably better for consistency, and then you can flip the reflect flag programmatically if you want: template <>
struct glz::meta<Color> {
static constexpr auto reflect = true;
}; |
Beta Was this translation helpful? Give feedback.
-
Ouu, yes, flipping would be nice. template <>
struct glz::meta<Color> {
static constexpr bool reflect = true;
static constexpr auto value = enumerate(...);
}; I would think precedence would be as follows, meaning the above would autoreflect, regardless of
|
Beta Was this translation helpful? Give feedback.
-
Agreed, I think |
Beta Was this translation helpful? Give feedback.
-
After thinking about this more, I think it is best to not add pure enum reflection until supported by C++26 (hopefully). Tagged enum values make this more complex. And, it bifurcates enum handling logic. It isn't hard to add a glz::meta also supports renaming enum values. As cool as enum reflection would be, we don't want pure reflection as the default (integers are default). So, any additional reflection approach would be deprecated in the future. I'm less eager to add features that I know will have deprecated APIs. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions