visit_struct icon indicating copy to clipboard operation
visit_struct copied to clipboard

Compatibility with cereal

Open mdimura opened this issue 6 years ago • 2 comments

Would it be possible to implement a compatibility layer for cereal similar to fusion/hana?

mdimura avatar Mar 30 '18 09:03 mdimura

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.

cbeck88 avatar Mar 30 '18 14:03 cbeck88

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

mdimura avatar Mar 30 '18 15:03 mdimura