|
Boost Users : |
Subject: [Boost-users] Adding indexes + serialization for MultiIndex
From: Sohail Somani (sohail_at_[hidden])
Date: 2013-02-27 12:52:49
I haven't actually happened upon this problem yet but I just want to
know if I know how to deal with it for the future.
My question is: how does the serialization work (or not work) if we add
or remove indexes from the type?
My suspicion is that one would have to do something like this:
// version 1:
BOOST_CLASS_VERSION(Thingy,1);
typedef multi_index_container<thing,indexes> myset1_t;
myset1_t m_MySet;
...
template<typename Ar>
void serialize(Ar & a, unsigned int)
{ ar & m_MySet; }
// version 2
BOOST_CLASS_VERSION(Thingy,2);
typedef multi_index_container<thing,indexes> myset1_t;
typedef multi_index_container<thing,indexes2> myset2_t;
myset2_t m_MySet; // using new version
...
template<typename Ar>
void serialize(Ar & a, unsigned int fv)
{
if(Ar::is_loading && fv == 1)
{
myset1_t set;
ar & set;
m_MySet.clear();
m_MySet.insert(m_MySet.begin(),set.begin(),set.end());
}
else
ar & m_MySet;
}
Would this be OK, errors in syntax aside?
Thanks,
Sohail
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net