Maybe i didn't express it clearly enough.
I want non-intrusive serialization.
I want to modify neither ContqinerClass, nor MemberClass.
(Both are just custom classes, no link with STL containers. I just wanted to express that Container contains an instance of Member)

So how can i write
ar & c.special_member;
since there is no serialize member function for this class?

And when i'll be using an non-intrusive (free function) serialize, how do i handle the version number?


On Mon, Mar 5, 2018 at 4:51 PM, Robert Ramey via Boost-users <boost-users@lists.boost.org> wrote:
On 3/5/18 5:12 AM, Lars Ruoff via Boost-users wrote:
Hi,
I have a class structure like

class MemberClass;

class ContainerClass {
   MemberClass special_member;
   int other_members;
};

Following the example in http://www.boost.org/doc/libs/1_66_0/libs/serialization/doc/
i want to write a non-intrusive serialization:

template<class Archive>
void serialize(Archive & ar, ContainerClass & c, const unsigned int version)
{
   ar & c.other_members; // easy - built-in type
   serialize(ar, c.special_member, version);  //use same version???
}

Assuming there's is also a non-intrusive
void serialize(Archive & ar, MemberClass & m, const unsigned int version);

this compiles and works but i feel this is not the way to do it because it reuses the version number of the container class for the member class? So how to handle that? Must the Container class manage version of its members individually?
I suggest to add a section "Non-intrusively Serializable Members" to documentation with an example.

Cheers,
Lars R.

I'm not sure what the "special member" of the container class is. Presumably it's your own class as STL classes have no "special members".  Assuming this to be the case there should be something like:

struct ContainerClass {
        ...
        void serialize(Achive &ar, const unsigned int v){
                ar & other_members;
                ar & special_member
        }
        ...
};

or

template<class Archive>
void serialize(Archive & ar, ContainerClass & c, const unsigned int version)
{
        ar & c.other_members; // easy - built-in type
        ar & c.special_member;
}


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users