简体   繁体   English

如何使用 boost::unordered_map 的 boost std::vector 序列化/反序列化

[英]How to serialize/deserialize with boost std::vector of boost::unordered_map

How to serialize/deserialize with boost std::vector of boost::unordered_map like如何使用 boost::unordered_map 的 boost std::vector 序列化/反序列化

vector<boost::unordered_map<uint64_t, Person* > *> town;

which represents town.代表城镇。 All pointers are row on heap created with new.所有指针都是用 new 创建的堆上的行。 Is possible to deserialize on easy way without refactoring code to use shared_ptr ?是否可以在不重构代码以使用 shared_ptr 的情况下以简单的方式反序列化? Person also has function also人也有功能

template<class Archive>
void serialize(Archive & archive, const unsigned int version){
...
}

unordered_* are not yet supported in Boost Serialization. Boost 序列化尚不支持 unordered_*。

Either add the support or use the (deprecated) GCC hash_* containers添加支持或使用(已弃用)GCC hash_* 容器

A sample of how to add support is in this answer of mine: C++ Boost.Serialization error for hash_map with custom objects as key如何添加支持的示例在我的这个答案中: C++ Boost.Serialization error for hash_map with custom objects as key

Boost has already supported the unordered_set and unordered_map since the version 1.5.6. Boost 从 1.5.6 版本开始支持unordered_setunordered_map You can just include the header file.您可以只包含头文件。

#include <boost/serialization/unordered_map.hpp>
#include <boost/serialization/unordered_set.hpp>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM