map.hpp 871 Bytes
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */
Matthieu Dorier's avatar
Matthieu Dorier committed
6 7
#ifndef __THALLIUM_MAP_SERIALIZATION_HPP
#define __THALLIUM_MAP_SERIALIZATION_HPP
8

Matthieu Dorier's avatar
Matthieu Dorier committed
9 10 11 12 13 14
#include <thallium/config.hpp>

#ifdef THALLIUM_USE_CEREAL
    #include <cereal/types/map.hpp>
#else

15 16 17 18 19
#include <map>

namespace thallium {

template<class A, typename K, typename V, class Compare, class Alloc>
20
inline void save(A& ar, std::map<K,V,Compare,Alloc>& m) {
21 22 23 24 25 26
    size_t size = m.size();
    ar.write(&size);
    for(auto& elem : m) {
        ar & elem.first;
        ar & elem.second;
    }
27 28 29
}

template<class A, typename K, typename V, class Compare, class Alloc>
30
inline void load(A& ar, std::map<K,V,Compare,Alloc>& m) {
31 32 33 34 35 36 37 38
    size_t size;
    ar.read(&size);
    m.clear();
    for(unsigned int i=0; i<size; i++) {
        K k;
        ar & k;
        ar & m[k];
    }
39 40 41 42 43
}

}

#endif
Matthieu Dorier's avatar
Matthieu Dorier committed
44
#endif