list.hpp 753 Bytes
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */
#ifndef __THALLIUM_LIST_SERIALIZATION_HPP
#define __THALLIUM_LIST_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/list.hpp>
#else

15 16 17 18 19
#include <list>

namespace thallium {

template<class A, typename T, typename Alloc>
20
inline void save(A& ar, std::list<T,Alloc>& l) {
21 22 23 24 25
    size_t size = l.size();
    ar.write(&size);
    for(auto& item : l) {
        ar & item;
    }
26 27 28
}

template<class A, typename T, typename Alloc>
29
inline void load(A& ar, std::list<T,Alloc>& l) {
30 31 32 33 34 35 36
    size_t size;
    l.clear();
    ar.read(&size);
    l.resize(size);
    for(auto& item : l) {
        ar & item;
    }
37 38 39 40 41
}

}

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