github stephenberry/glaze v7.2.0

latest releases: v8.4.0, v8.3.0, v8.2.0...
6 months ago

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::meta needed, 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_enums option 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.

Improvements

  • Make stream_request buffer size configurable + update docs by @frak0d in #2354

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

  • @nghiaho310pf made their first contribution in #2359
  • @frak0d made their first contribution in #2354

Full Changelog: v7.1.1...v7.2.0

Don't miss a new glaze release

NewReleases is sending notifications on new releases.