user957121
user957121

Reputation: 3066

Compile error on serializing boost::unordered_set

First of all, Does boost::serialization support unordered_set now? I didn't find the header boost/serialization/unordered_set.hpp.

Here is the code I tried to implement:

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);
}

}
}

Here is the error:

'class std::vector<int, std::allocator<int> >' has no member named 'serialize'

Plus, I still got a warning on the following code:

boost::archive::text_oarchive(ss)<<s1; 

Warning:comparison between signed and unsigned integer expressions [-Wsign-compare]

I'm not sure whether it's Ok to neglect it.

Upvotes: 3

Views: 1179

Answers (1)

balas bellobas
balas bellobas

Reputation: 237

To answer your first question, there is no serialization support form the boost library for serializing boost.unordered containers.

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

Upvotes: 2

Related Questions