C++26 Reflection Support!
Glaze now supports P2996 "Reflection for C++26". This unlocks capabilities that aren't possible with older compile-time reflection:
- Non-aggregate types — classes with constructors, virtual functions, and inheritance just work
- Automatic enum serialization — no
glz::metaneeded, enums serialize to strings automatically - Unlimited struct members — no 128-member cap
- Private member access — reflect on all members regardless of access specifiers
- Standardized — no compiler-specific hacks, built on
std::meta
// Classes with constructors — just works with P2996
class User {
public:
std::string name;
int age;
User() = default;
User(std::string n, int a) : name(std::move(n)), age(a) {}
};
User u{"Alice", 30};
auto json = glz::write_json(u).value_or("error");
// {"name":"Alice","age":30}
// Enums serialize as strings — no glz::meta required
enum class Color { Red, Green, Blue };
Color c = Color::Green;
struct reflect_enums_opts : glz::opts {
bool reflect_enums = true;
};
auto color_json = glz::write<reflect_enums_opts{}>(c).value_or("error");
// "Green"Note that the
reflect_enumsoption has been added to avoid a breaking change for how Glaze default serializes enums as their numerical equivalent.
Supported compilers: GCC 16+ (-std=c++26 -freflection) and Bloomberg clang-p2996. See the C++26 reflection documentation for setup and details.
- C++26 Reflection by @stephenberry in #2217
Improvements
Fixes
- YAML fix for unindented sequence under a known key by @stephenberry in #2357
- Fix YAML double-quoted \xXX being interpreted as a byte instead of a codepoint by @nghiaho310pf in #2359
- YAML Fixes and Improvements by @stephenberry in #2358
New Contributors
Full Changelog: v7.1.1...v7.2.0