序列化boost :: unordered_set时编译错误

时间:2013-05-01 08:28:28

标签: c++ serialization boost boost-serialization unordered-set

首先,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]

我不确定是否可以忽略它。

1 个答案:

答案 0 :(得分:2)

要回答您的第一个问题,升级库中没有用于序列化boost.unordered容器的序列化支持。

http://meetingcpp.com/index.php/talkview13/items/2.html