JOAQUIN LOPEZ MU?Z wrote:
Hello Robert,
----- Mensaje original ----- De: Robert Ramey
Fecha: Sábado, Septiembre 16, 2006 8:01 am Asunto: Re: [Boost-users] [serialization] serialization of pointers to primitive types? Serialization of pointers to primitive data types is prohibited. I'm pretty sure this is mentioned in the documentation. ( don't have the exact reference handy)
I've persued the docs and in every place where this is referred to, the statement is that primitive types are not tracked, which is IMHO different than serialization of pointers to primitive types being forbidden. Examples:
- Serializable concept:
"A type T is Serializable if and only if one of the following is true: * it is a primitive type. [...] * it is a pointer to a Serializable type.[...]"
from which it can be deduced that a pointer to a primitive type is serializable.
Touche
- Object tracking:
"Default tracking traits are: * For primitive, track_never.[...]"
At the risk of repeating myself, I understand what serializing a pointer to a non-tracked type involves. This is not the same as not being able to serialize the pointer in the first place, which is what happens with primitive types, to my dismay.
Correct, I lumped the two ideas - serialization and tracking together in my brain. Clearly an error.
Wouldn't it be an option that pointers to primitive types will be handled as non-tracked? What would be the overhead of that option? In case this is an option, please consider my vote for inclusion as a new feature in Boost 1.35.
OK - that would work fine - but I also believe it would trip the infamous "const trap" so that might have to be considered.
The way to serialize pointer to primitives (serialization_level::prmitive) is to use BOOST_STRONG_TYPEDEF to define a new type and specify serialization function for it. This won't work for std::string so you'll have to make a trivial derivation of std::string if you want to serialize a pointer to a std::string.
The problem with that is that it is an intrusive solution that complicates things when dealing with generic code. Sometimes, it can be just impossible to do that intrusive change or require the user to do it. From this restriction, for instance, we have that
std::set
is not serializable as is. Telling the user to change her definition to something like
std::set
just for the sake of serializability could be unacceptable in some (many?) situations.
Note that I like the BOOST_STRONG_TYPEDEF for a number
of reasons. Basically it attaches more information to an int at compile
time and this makes generic programming easier. So my reaction is
if you're serializing std::set