首先, boost::serialization 现在支持 unordered_set 吗?我没有找到标题 boost/serialization/unordered_set.hpp。
这是我尝试实现的代码:
namespace boost {
namespace serialization{
template<class Archive, typename T, typename H, typename P, typename A>
void save(Archive &ar,
const unordered::unordered_set<T,H,P,A> &s, const unsigned int) {
vector<T> vec(s.begin(),s.end());
ar<<vec;
}
template<class Archive, typename T, typename H, typename P, typename A>
void load(Archive &ar,
unordered::unordered_set<T,H,P,A> &s, const unsigned int) {
vector<T> vec;
ar>>vec;
std::copy(vec.begin(),vec.end(),
std::inserter(s,s.begin()));
}
template<class Archive, typename T, typename H, typename P, typename A>
void serialize(Archive &ar,
unordered::unordered_set<T,H,P,A> &s, const unsigned int version) {
boost::serialization::split_free(ar,s,version);
}
}
}
这是错误:
'class std::vector<int, std::allocator<int> >' has no member named 'serialize'
另外,我仍然收到以下代码的警告:
boost::archive::text_oarchive(ss)<<s1;
Warning:comparison between signed and unsigned integer expressions [-Wsign-compare]
我不确定是否可以忽略它。