Skip to content
Discussion options

You must be logged in to vote

Here's an example using glz::generic within a similar approach to glz::custom that you were aiming for:

https://gcc.godbolt.org/z/s4G5q56fd

#include <iostream>
#include <variant>

#include "glaze/glaze.hpp"

namespace attributes {
struct none {};

struct a {
    std::string aa;
    float ab;
};

struct b {
    std::string ba;
    std::string bb;
};

using variant = std::variant<none, a, b>;
}  // namespace attributes

struct node {
    std::string id;
    std::string node_type;
    attributes::variant attributes;
};

// Robust parsing that doesn't depend on JSON field order
template <>
struct glz::meta<node> {
    using T = node;

    // Read the entire node from generic JSON
    static c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@stephenberry
Comment options

@Sephirothbahamut
Comment options

Answer selected by stephenberry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants