
Hello, I am trying to use boost::archive::xml_oarchive to serialize a vector<map<string, map<string,int> > >. When I examine the serialized xml file, I see that some of the map elements are duplicated which causes an assertion when I try to load the file because a map cannot have two elements with the same key. I would appreciate any insight into this error. Thank you Thomas D'Silva /include/boost/serialization/collections_load_imp.hpp:69: void boost::serialization::stl::archive_input_map<Archive, Container>::operator()(Archive&, Container&) [with Archive = boost::archive::xml_iarchive, Container = std::map<std::string, int, std::less<std::string>, std::allocator<std::pair<const std::string, int> > >]: Assertion `result.second' failed. #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> #include <boost/serialization/vector.hpp> #include <boost/serialization/map.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/nvp.hpp> using namespace std; using namespace boost::filesystem; class DistributionTable { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(neTable); ar & BOOST_SERIALIZATION_NVP(mappedTable); } vector<map<string,map<string,int> > > neTable; vector<map<string,map<string,int> > > mappedTable; public: DistributionTable(){}; }; void saveTable(const DistributionTable &t, string filename) { ofstream ofs(filename.c_str()); boost::archive::xml_oarchive oa(ofs); oa <<BOOST_SERIALIZATION_NVP(t); ofs.flush(); } void loadTable(DistributionTable &t, string filename) { ifstream ifs(filename.c_str()); boost::archive::xml_iarchive ia(ifs); ia >>BOOST_SERIALIZATION_NVP(t); }