[serialization] bug? serializing a vector resets ignored element members

Hi
If I serialize a struct, while ignoring one of its members, the member
retains its value. I understand that this is the inteded serialization
semantics - what you ignore for reading and writing remains intact.
However, if I do this with a vector, the ingored members of its
elements get reset to their "default" values.
I'm too lazy to pore over the sources, but I'm guessing this might be
happening because the implementation of vector serialization calls its
constructor (and assignment?) where a resize could probably be better.
Here is the specific code I boiled down the manifestation of this
feature/bug to:
// creates writes "remove_me" file
#include <iostream>
#include <fstream>
#include <vector>
#include

n.torrey.pines@gmail.com wrote:
I'm too lazy to pore over the sources, but I'm guessing this might be happening because the implementation of vector serialization calls its constructor (and assignment?)
Good guess - probably correct
where a resize could probably be better.
Hmm - maybe or maybe not. That would raise the issue of what to do about std::map and others that can't be "fixed" this way. Fixing vector would leave a situation where behavior varied according to what kind of collection the instance was an element of. Still an interesting question. I suspect it hasn't come up until now as the "un serialized members" are usually not important enough to serialize not important enough to save the values. If this behavior is important to you, I think the best would be to implement your own variation of serialization for std::vector. I'm sure you would find this very easy using the current implementation as a basis. Robert Ramey
participants (2)
-
n.torrey.pines@gmail.com
-
Robert Ramey