Robert Ramey wrote:
Sohail Somani wrote:
Still interested in forward compatibility, if you are inclined to elaborate a little.
Here we go. Basically, backward compatibility is handled by code that looks like the following:
template<class Archive> void save(Archive &ar, const unsigned int version){ ar << original_stuff ar << stuff_added_version_3; ar << stuff_added_version_4; }
template<class Archive> void load(Archive &ar, const unsigned int version){ ar >> original_stuff; if(version > 3) ar >> stuff_added_version_3; if(version > 4) ar >> stuff_added_version_4; ... }
So what we need to do is replace the save above with:
template<class Archive> void save(Archive &ar, const unsigned int version) const { ar << original_stuff if(version > 3) ar << stuff_added_version_3; if(version > 4) ar << stuff_added_version_4; }
Just typing out loud: Forward compatibility is the ability to load an archive with a version of 4 into an application with a version of 3. So if we have std::vector<SomeClass> and in version 4, I add an int to SomeClass, I'm pretty sure it would cause the whole thing to go boom when loading an archive from version 4 into version 3. I'm not sure if the above avoids this problem, does it? -- Sohail Somani http://uint32t.blogspot.com