visit_struct
visit_struct copied to clipboard
Compatibility with cereal
Would it be possible to implement a compatibility layer for cereal similar to fusion/hana?
Hi,
I've looked at Cereal in the past, but not too recently. IIRC it's like, you add the visitation function to your struct, so,
struct my_struct {
int a;
float b;
double c;
template <typename A>
void archive(A & archiver) {
archiver(a);
archiver(b);
archiver(c);
}
};
and then Cereal picks up on the existence of the archive
template member function and uses it to visit the struct.
I think that visit_struct
cannot create a compatibility layer like with Fusion and Hana to this API, because it gives me no way to determine the struct member names.
However, maybe we can make a patch in Cereal, so that if your struct does not have an ::archive
function, then it checks if it is a visitable structure and tries to use the visit_struct
api instead? Cereal would then also get the benefit of the hana and fusion compat layers I think.
It seems, you are right. I think, a patch for Cereal would be great. Thank you for the response!
no way to determine the struct member names.
Yep, apparantly, Cereal uses default names like value0
if no other name is provided:
archive( CEREAL_NVP(m1), // Names the output the same as the variable name
someInt, // No NVP - cereal will automatically generate an enumerated name
cereal::make_nvp("this_name_is_way_better", d) ); // specify a name of your choosing