|
Boost Users : |
Subject: [Boost-users] [serialization] [multimap] change of element's order when deserialize
From: Pablo Madoery (madoerypablo_at_[hidden])
Date: 2014-04-09 10:45:59
I have the following code:
#include <utility>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <map>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/map.hpp>
using namespace std;
void print(multimap<pair<string, string>, int> &m)
{
multimap<pair<string, string>, int>::iterator it1 = m.begin();
multimap<pair<string, string>, int>::iterator it2 = m.end();
for(; it1!=it2; ++it1)
{
cout<<"key = "<<(it1->first).first<<(it1->first).second<<"\t\t";
cout<<"value = "<<(it1->second)<<endl;
}
cout<<endl;
}
int main()
{
multimap<pair<string, string>, int> m1;
pair<string, string> par1("A", "B");
pair<string, string> par2("A", "B");
pair<string, string> par3("E", "F");
pair<string, string> par4("E", "F");
m1.insert(pair<pair<string, string>, int>(par1,10));
m1.insert(pair<pair<string, string>, int>(par2,20));
m1.insert(pair<pair<string, string>, int>(par3,30));
m1.insert(pair<pair<string, string>, int>(par4,40));
ofstream ofs("filename");
boost::archive::text_oarchive serial1(ofs);
serial1 << m1;
ofs.close();
ifstream ifs("filename");
boost::archive::text_iarchive serial2(ifs);
multimap<pair<string, string>, int> m2;
serial2 >> m2;
cout<<"map1 = "<<endl;
print(m1);
cout<<endl;
cout<<"map2 = "<<endl;
print(m2);
cout << "end" << endl;
return 0;
}
What I am trying to do is serialize a multimap and then deserialize it.
The problem i that the order of the elements is not conserved.
This program gives as result the following:
map1 =
key = AB value = 10
key = AB value = 20
key = EF value = 30
key = EF value = 40
map2 =
key = AB value = 20
key = AB value = 10
key = EF value = 40
key = EF value = 30
end
where you can see that the element's order is changed.
When compiling it throw this warning:
boost::mpl::print<boost::serialization::BOOST_SERIALIZATION_STATIC_WARNING_LINE<98>
>
that I don't know what it means.
Is this a normal behavior of the serialization library?
I am missing something ?
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