Consider a structure to serialize:
struct MyStruct {
int a;
std::string b;
template<class Archive>
void serialize(Archive &ar, const unsigned int)
{
ar & a & b;
}
};
I want to explicitly tag it, using boost::serialization::traits, to be both track_never and object_serializable. I’ve stared at the traits docs, but can’t seem to get my mind around how to apply it, and can’t find an example anywhere. So…
a) What’s the code that applies traits to this particular class?
b) What’s the BOOST_STATIC_ASSERT() that verifies each is in place?
c) I assume I can’t make this class primitive_type since there’s no member function or template in a typical archive class that can handle this type directly. Correct?
I don’t care about cross-platform or cross-version archive compatibility, just fast reads (and writes) and intruding on MyStruct is OK, but it would be nice to see it done both ways if possible.
Since
MyStructis not a templatized struct or class to apply the the traits all you need to do is use the BOOST_CLASS_IMPLEMENTATION and BOOST_CLASS_TRACKING macros:Outside of your class definition you’d need to write the following two lines:
A BOOST_STATIC_ASSERT() to verify you’re doing the right thing looks like:
I would say it doesn’t make sense to make this a primitive type because its not a primitive type.