tuple.hpp 1.02 KB
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_TUPLE_SERIALIZATION_HPP
#define __THALLIUM_TUPLE_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/tuple.hpp>
#else

15 16 17 18 19 20 21 22 23
#include <tuple>

namespace thallium {

namespace detail {

template<size_t N>
struct tuple_serializer {

24
    template<class A, class... Types>
25
    static inline void apply(A& ar, std::tuple<Types...>& t) {
26 27 28
        tuple_serializer<N-1>::apply(ar,t);
        ar & std::get<N-1>(t);
    }
29 30 31 32 33
};

template<>
struct tuple_serializer<0> {

34
    template<class A, class... Types>
35
    static inline void apply(A& ar, std::tuple<Types...>& t) {}
36 37 38 39 40
};

}

template<class A, class... Types>
41
inline void save(A& ar, std::tuple<Types...>& t) {
42
    detail::tuple_serializer<sizeof...(Types)>::apply(ar,t);
43 44 45
}

template<class A, typename... Types>
46
inline void load(A& ar, std::tuple<Types...>& t) {
47
    detail::tuple_serializer<sizeof...(Types)>::apply(ar,t);
48 49 50 51 52
}

}

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