set.hpp 585 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#ifndef THALLIUM_SET_SERIALIZATION_H
#define THALLIUM_SET_SERIALIZATION_H

#include <utility>
#include <set>

namespace thallium {

template<class A, typename T, class Compare, class Alloc>
void save(A& ar, std::set<T,Compare,Alloc>& s) {
	size_t size = s.size();
	ar.write(&size);
	for(auto& elem : s) {
		ar & elem;
	}
}

template<class A, typename T,  class Compare, class Alloc>
void load(A& ar, std::set<T,Compare,Alloc>& s) {
	size_t size;
	s.clear();
	ar.read(&size);
	for(int i=0; i<size; i++) {
		T item;
		ar & item;
		s.insert(std::move(item));
	}
}

} // namespace

#endif