r/cpp • u/Flex_Code • Mar 12 '26
Glaze 7.2 - C++26 Reflection | YAML, CBOR, MessagePack, TOML and more
Glaze is a high-performance C++23 serialization library with compile-time reflection. It has grown to support many more formats and features, and in v7.2.0 C++26 Reflection support has been merged!
GitHub: https://github.com/stephenberry/glaze | Docs
C++26 Reflection (P2996)
Glaze now supports C++26 reflection with experimental GCC and Clang compilers. GCC 16 will soon be released with this support. When enabled, Glaze replaces the traditional __PRETTY_FUNCTION__ parsing and structured binding tricks with proper compile-time reflection primitives (std::meta).
The API doesn't change at all. You just get much more powerful automatic reflection that still works with Glaze overrides! Glaze was designed with automatic reflection in mind and still lets you customize reflection metadata using glz::meta on top of what std::meta provides via defaults.
What C++26 unlocks
- Unlimited struct members — Glaze used to be capped at 128 members via structured binding limits.
- Non-aggregate types — Classes with custom constructors, virtual functions, and private members can all be reflected automatically.
- Automatic inheritance — Base class members are included automatically. No
glz::metaspecialization needed. - Automatic enum serialization — Enums serialize as strings without any metadata.
Here's an example of non-aggregate types working out of the box:
class ConstructedClass {
public:
std::string name;
int value;
ConstructedClass() : name("default"), value(0) {}
ConstructedClass(std::string n, int v) : name(std::move(n)), value(v) {}
};
// Just works with P2996 — no glz::meta needed
std::string json;
glz::write_json(ConstructedClass{"test", 42}, json);
// {"name":"test","value":42}
Inheritance is also automatic:
class Base {
public:
std::string name;
int id;
};
class Derived : public Base {
public:
std::string extra;
};
std::string json;
glz::write_json(Derived{}, json);
// {"name":"","id":0,"extra":""}
constexpr auto names = glz::member_names<Derived>;
// {"name", "id", "extra"}
New Data Formats
Since my last post about Glaze, we've added four new serialization formats. All of them share the same glz::meta compile-time reflection, so if your types already work with glz::write_json/glz::read_json, they work with every format. And these formats are directly supported in Glaze without wrapping other libraries.
YAML (1.2 Core Schema)
struct server_config {
std::string host = "127.0.0.1";
int port = 8080;
std::vector<std::string> features = {"metrics", "logging"};
};
server_config config{};
std::string yaml;
glz::write_yaml(config, yaml);
Produces:
host: "127.0.0.1"
port: 8080
features:
- "metrics"
- "logging"
Supports anchors/aliases, block and flow styles, full escape sequences, and tag validation.
CBOR (RFC 8949)
Concise Binary Object Representation. Glaze's implementation supports RFC 8746 typed arrays for bulk memory operations on numeric arrays, multi-dimensional arrays, Eigen matrix integration, and complex number serialization.
MessagePack
Includes timestamp extension support with nanosecond precision and std::chrono integration.
TOML (1.1)
struct product {
std::string name;
int sku;
};
struct catalog {
std::string store_name;
std::vector<product> products;
};
std::string toml;
glz::write_toml(catalog{"Hardware Store", {{"Hammer", 738594937}}}, toml);
Produces:
store_name = "Hardware Store"
[[products]]
name = "Hammer"
sku = 738594937
Native std::chrono datetime support, array of tables, inline table control, and enum handling.
Lazy JSON (and Lazy BEVE)
glz::lazy_json provides on-demand parsing with zero upfront work. Construction is O(1) — it just stores a pointer. Only the bytes you actually access get parsed.
std::string json = R"({"name":"John","age":30,"scores":[95,87,92]})";
auto result = glz::lazy_json(json);
if (result) {
auto& doc = *result;
auto name = doc["name"].get<std::string_view>(); // Only parses "name"
auto age = doc["age"].get<int64_t>(); // Only parses "age"
}
For random access into large arrays, you can build an index in O(n) and then get O(1) lookups:
auto users = doc["users"].index(); // O(n) one-time build
auto user500 = users[500]; // O(1) random access
You can also deserialize into structs directly from a lazy view:
User user{};
glz::read_json(user, doc["user"]);
HTTP Server, REST, and WebSockets
Glaze now includes a full HTTP server with async ASIO backend, TLS support, and WebSocket connections.
Basic server
glz::http_server server;
server.get("/hello", [](const glz::request& req, glz::response& res) {
res.body("Hello, World!");
});
server.bind("127.0.0.1", 8080).with_signals();
server.start();
server.wait_for_signal();
Auto-generated REST endpoints using reflection
You can register C++ objects and Glaze will automatically generate REST endpoints from reflected methods:
struct UserService {
std::vector<User> getAllUsers() { return users; }
User getUserById(size_t id) { return users.at(id); }
User createUser(const User& user) { users.push_back(user); return users.back(); }
};
glz::registry<glz::opts{}, glz::REST> registry;
registry.on(userService);
server.mount("/api", registry.endpoints);
Method names are mapped to HTTP methods automatically — get*() becomes GET, create*() becomes POST, etc.
WebSockets
auto ws_server = std::make_shared<glz::websocket_server>();
ws_server->on_message([](auto conn, std::string_view msg, glz::ws_opcode opcode) {
conn->send_text("Echo: " + std::string(msg));
});
server.websocket("/ws", ws_server);
6
u/daniel_nielsen Mar 12 '26
One of my favourite libraries got better! Currently I only have GCC-15.
Can someone with the appropriate environment run a quick test with the compilation time when using this version with C++26 Reflection compared with the glaze legacy reflection? Am really excited by this and what the future will hold.
21
u/bbmario Mar 12 '26
Glaze is the most exciting thing in C++ land lately. stephenberry is a legend.
18
u/torrent7 Mar 12 '26
Amazing library
14
u/greencursordev Mar 12 '26
I'm so confused about the Webserver Part. I mean great, I love it. But how does it fit in with data format de/serialisation? Why not a different library?
13
u/throwawayaqquant Mar 12 '26
Please consider standardizing your library, as i would hate to see something based on nlohmann design become the C++ standards' json
23
u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Mar 12 '26
Very cool to see reflection showing up in this library. A great use case for it.
4
u/Realistic-Reaction40 Mar 13 '26
The unlimited struct members alone makes this worth upgrading for hitting the 128 member limit with structured bindings was always an awkward constraint. The automatic inheritance support is going to clean up a lot of glz::meta boilerplate in codebases that use deep class hierarchies.
1
u/HALOGEN117 Mar 17 '26
I've been trying to use this with MSVC, but every time I build the project I get about hundreds of build errors, pain
2
u/msew Mar 12 '26
Wow!! This looks amazing!!!
2
u/_Noreturn Mar 12 '26
nice, pretty function tricks are so annoying to work with and limitting.
2
u/skiboysteve Mar 13 '26
Very cool