glz::reflectable<T> fails when glz::meta<T> is explicitly declared, is it the expected behaviour? #1844
-
|
Declaring glz::meta explicitly seems to break glz::reflectable — despite the struct being obviously reflectable. Surprisingly, removing the glz::meta specialization makes it pass all reflect and reflectable checks. i'm not sure if it's the same with #721 but defining glz::make_reflectable c-tor doesn't help. The problem occured when i tried to make from python dict function like that, just to check out if I can make python work with glaze, just for fun. // Map py::dict to Payload using field reflection
template <typename T> T from_dict(const py::dict &dict) {
T obj{};
std::size_t idx = 0;
glz::for_each_field(obj, [&](auto &field) {
using FieldType = std::remove_cvref_t<decltype(field)>;
const auto &key = glz::reflect<T>::keys[idx++];
std::cout << "Processing key: " << key
<< ", Type: " << typeid(FieldType).name()
<< ", is reflectable: " << glz::reflectable<FieldType>;
if (dict.contains(key.data())) {
if constexpr (glz::reflectable<FieldType>) {
std::cout << " reflectable" << std::endl;
field = from_dict<FieldType>(dict[key.data()]);
} else {
std::cout << " usual" << std::endl;
field = py::cast<std::decay_t<decltype(field)>>(dict[key.data()]);
}
}
});
return obj;
}which just failed because i cant cast field to (struct Nested) because FieldType isn't considered reflectable, which can be checked with static assert |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Might I ask for help please? |
Beta Was this translation helpful? Give feedback.
-
|
Sorry for overlooking this. |
Beta Was this translation helpful? Give feedback.
Sorry for overlooking this.
glz::reflectable<T>indicates that the type should use pure reflection. When aglz::metais defined this can be checked viaglz::glaze_object_t<T>. So, Glaze code for JSON objects tends to use:glaze_object_t<T> || reflectable<T>. You probably want to use these two concepts together.