Consider this JSON example:
...
"cameras" : [
{
"type": "perspective",
"perspective": {
"aspectRatio": 1.0,
"yfov": 0.7,
"zfar": 100,
"znear": 0.01
}
},
{
"type": "orthographic",
"orthographic": {
"xmag": 1.0,
"ymag": 1.0,
"zfar": 100,
"znear": 0.01
}
}
],
...
I want to serialize/deserialize each cameras with the following structs:
struct OrthographicCamera {
float xmag;
float ymag;
float zfar;
float znear;
};
struct PerspectiveCamera {
std::optional<float> aspectRatio;
float yfov;
std::optional<float> zfar;
float znear;
};
struct Camera {
std::string_view name;
std::variant<PerspectiveCamera, OrthographicCamera> camera;
};
template <>
struct glz::meta<std::variant<ggltf::PerspectiveCamera, ggltf::OrthographicCamera>> {
static constexpr std::string_view tag = "type";
static constexpr std::array ids { "perspective", "orthographic" };
// static constexpr std::string_view content = ?;
};
But this is not possible with the current glaze variant handling mechanism: alternative tag name is determined by type, so a single fixed content cannot be specified.
It would be good if the type of content could be array of std::string_view (whose length must be as same as the ids), like:
template <>
struct glz::meta<std::variant<ggltf::PerspectiveCamera, ggltf::OrthographicCamera>> {
static constexpr std::string_view tag = "type";
static constexpr std::array ids { "perspective", "orthographic" };
static constexpr std::array content { "perspective", "orthographic" };
};
Consider this JSON example:
I want to serialize/deserialize each cameras with the following structs:
But this is not possible with the current glaze variant handling mechanism: alternative tag name is determined by
type, so a single fixedcontentcannot be specified.It would be good if the type of
contentcould be array ofstd::string_view(whose length must be as same as theids), like: