以下のコードは、クラスと構造体のメンバーをシリアライズしてシリアライズしています。 シリアライゼーションは動作していますが、デシリアライズしようとしているときに以下のエラーが発生しましたoarch >> BOOST_SERIALIZATION_NVP(outObj);
コードに大きな不具合がありますか?static_assertがブーストを使用してバイナリデータをデシリアライズしているときに "typex :: value"エラーが発生しました
In file included from main.cpp:1: In file included from /usr/local/include/boost/archive/binary_oarchive.hpp:21: In file included from /usr/local/include/boost/archive/binary_oarchive_impl.hpp:22: In file included from /usr/local/include/boost/archive/basic_binary_oarchive.hpp:33: In file included from /usr/local/include/boost/archive/detail/common_oarchive.hpp:22: In file included from /usr/local/include/boost/archive/detail/interface_oarchive.hpp:23: In file included from /usr/local/include/boost/archive/detail/oserializer.hpp:68: /usr/local/include/boost/archive/detail/check.hpp:162:5: error: static_assert failed "typex::value" BOOST_STATIC_ASSERT(typex::value); ^ ~~~~~~~~~~~~ /usr/local/include/boost/static_assert.hpp:70:41: note: expanded from macro 'BOOST_STATIC_ASSERT'
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/binary_object.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <map>
#include <boost/serialization/map.hpp>
#include <boost/serialization/split_member.hpp>
struct values
{
std::string name;
std::string sex;
values():name("dummy"),sex("dummy"){} ;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(name);
ar & BOOST_SERIALIZATION_NVP(sex);
}
};
class Myclass
{
public:
Myclass()
{
values val1;
e_group.insert(std::make_pair(1,val1)) ;
e_group.insert(std::make_pair(2,val1)) ;
p_group.insert(std::make_pair(1,e_group)) ;
p_group.insert(std::make_pair(2,e_group)) ;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) const
{
ar & BOOST_SERIALIZATION_NVP(e_group);
ar & BOOST_SERIALIZATION_NVP(p_group);
}
typedef std::map<int,values> groups;
typedef std::map<int,groups> Pgroups;
groups e_group;
Pgroups p_group;
};
int main()
{
Myclass assetlist;
auto os = std::ostringstream(std::ios::binary);
boost::archive::binary_oarchive arch(os, boost::archive::no_header);
arch << BOOST_SERIALIZATION_NVP(assetlist);
std::string s1 = os.str();
std::stringstream is(s1, std::ios_base::binary| std::ios_base::out| std::ios_base::in);
Myclass outObj;
boost::archive::binary_iarchive iarch (is , boost::archive::no_header);
iarch >> BOOST_SERIALIZATION_NVP(outObj);
return 0;
}
ありがとう、ありがとう – LearningCpp