GCC and Clang glz::meta reflection!
In the past you were required to write out the key name along with the member object pointer in your glz::meta definition. As of 1.8.0, on GCC and Clang the key names are entirely optional. You can individually include custom key names as needed, but otherwise simple reflection will use the name of your member variable.
Instead of writing:
template <>
struct glz::meta<my_struct> {
using T = my_struct;
static constexpr auto value = object(
"i", &T::i,
"d", &T::d,
"hello", &T::hello,
"arr", &T::arr
);
};You can now write:
template <>
struct glz::meta<my_struct> {
using T = my_struct;
static constexpr auto value = object(
&T::i,
&T::d,
&T::hello,
&T::arr
);
};- This update has zero runtime performance overhead!
- Every field can be individually named and customized as before
- The reflection is very simple and doesn't use esoteric hacks
- The reflection works on all types, non-aggregates, non-default constructible, non-constexpr etc.
NOTE: If you want comments in your
glz::metawithout providing key names, you must denote those comments explicitly. Glaze now has acommenttype and a_cliteral for denoting comments. These explicit comments are only needed if you remove the key name.
template <>
struct glz::meta<my_struct> {
using T = my_struct;
static constexpr auto value = object(
&T::i, "i is an integer"_c,
&T::d, comment("d is a double"),
&T::hello, "hello is a string"_c,
&T::arr, comment("this is an array of integers")
);
};This support is currently only for JSON. Next steps will be adding reflection support for wrappers and BEVE.