
Robert Ramey wrote:
This is what boost variant serialization does.
Robert Ramey
I suspected as much. Probably a bit more elegant than my brute force implementation though. I also suspect that OP already has something similar to that bool I added. If so, he doesn't need to add another bool to serialize the union; just make sure he serializes enough members to know which union member is valid before serializing that member. Either that or he uses the union to directly access the bits in the float. If that's the case, he can just serialize the float and be done with it. Andrew Holden wrote:
union myunion {
uint32_t a; float t; The best solutions would become more obvious if you know which type is valid at a higher level. For example, if you have a structure
niranjan bangera wrote: like this:
struct UnionWrapper { myunion the_union; bool is_float; /* Set to true if and only if the float member is used */
template <class Archive> void serialize (Archive &ar, unsigned int const version) { ar & is_float; /*Do this first so deserialization knows which union member to get. */
if (is_float) { ar & the_union.t; } else { ar & the_union.a; } } };
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users