Syntax error when extending glz::json_t with glm types #1333
-
Hey, I've been trying to customize using val_t = std::variant<null_t, std::string, bool, array_t, object_t, double, glm::vec2>;
// ...
// Meta impl. for my custom types, outside of 'MyCustomJson' struct
template<>
struct glz::meta<glm::vec2> {
static constexpr std::string_view name = "glm::vec2";
using T = glm::vec2;
static constexpr auto value = object(&T::x, &T::y);
}; For some reason, variant_is_auto_deducible always evaluates to false thus causing a weird error like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Exact location of where syntax error is set at: glaze/include/glaze/json/read.hpp Line 447 in 6d249bf
|
Beta Was this translation helpful? Give feedback.
-
The parsing is failing there because the variant isn't auto-deducible and thus defaults to You're correct that your meta for The easiest solution is probably to just use I also think I should add a |
Beta Was this translation helpful? Give feedback.
The parsing is failing there because the variant isn't auto-deducible and thus defaults to
null_t
and tries to parse into thisnull_t
, which is why it is erroring in the specialization foralways_null_t
.You're correct that your meta for
glm::vec2
is conflicting withobject_t
, since both are objects (meta<glm::vec2>
:object(&T::x, &T::y);
).The easiest solution is probably to just use
glz::json_t
and then you can callif (value.contains("x") && value.contains("y"))
this should indicate that you have aglm::vec2
. There is an active issue open to support reading aglz::json_t
value into a concrete C++ struct here. This would be useful for you as well. Currently you would have to write the v…