cereal
cereal copied to clipboard
reflection with cereal similar to RTTR, Qt Property System or BOOST_HANA_DEFINE_STRUCT
I'm wondering if it would be possible/useful for cereal to provide something like:
struct MyClass
{
int n;
float f;
template<class Archive>
void serialize(Archive & archive)
{
archive( CEREAL_NVP(n), CEREAL_NVP(f) );
}
};
int main()
{
MyClass obj;
//boost::hana
cereal::for_each(cereal::properties(obj), [&](auto name, auto value) {
std::cout << name<< '=' << value << "\n";
});
//Qt properties
const int nVal=cereal::propertyCount(obj);
for(auto i=0; i<nVal; ++i) {
std::string name = cereal::propertyName(ojb, i);
auto val = cereal::property(ojb, i); //std::variant<int,float> or std::any ?
std::cout << name << "=" << some_convert(val) << "\n";
}
cereal::setProperty(obj, "n", 42);
cereal::setProperty<1>(obj, 3.14f);
}
Qt Property System boost::hana RTTR
I can imagine doing this in a very ugly and inefficient way through JSON...Archive, but maybe we could have some kind of more efficient PropertyAccessArchive?
Sounds like this: https://github.com/USCiLab/cereal/issues/713