mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Unit tests for std::tuple, fixed tuple serialization
Boost check for tuple serialization check could be made better, pair probably the same as well. boost doesn't like pairs or tuples in BOOST_CHECK_EQUAL
This commit is contained in:
@@ -10,17 +10,25 @@ namespace cereal
|
||||
namespace tuple_detail
|
||||
{
|
||||
// unwinds a tuple to save it
|
||||
template <size_t Height, class Archive, class ... Types> inline
|
||||
void serialize( Archive & ar, std::tuple<Types...> & tuple )
|
||||
template <size_t Height>
|
||||
struct serialize
|
||||
{
|
||||
ar & std::get<Height - 1>( tuple );
|
||||
serialize<Height - 1>( ar, tuple );
|
||||
}
|
||||
template <class Archive, class ... Types> inline
|
||||
static void apply( Archive & ar, std::tuple<Types...> & tuple )
|
||||
{
|
||||
ar & std::get<Height - 1>( tuple );
|
||||
serialize<Height - 1>::template apply( ar, tuple );
|
||||
}
|
||||
};
|
||||
|
||||
// Zero height specialization - nothing to do here
|
||||
template <class Archive, class ... Types> inline
|
||||
void serialize<0, Types...>( Archive & ar, std::tuple<Types...> & tuple )
|
||||
{ }
|
||||
template <>
|
||||
struct serialize<0>
|
||||
{
|
||||
template <class Archive, class ... Types> inline
|
||||
static void apply( Archive & ar, std::tuple<Types...> & tuple )
|
||||
{ }
|
||||
};
|
||||
}
|
||||
|
||||
//! Serializing for std::tuple to binary
|
||||
@@ -28,7 +36,7 @@ namespace cereal
|
||||
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
|
||||
serialize( Archive & ar, std::tuple<Types...> & tuple )
|
||||
{
|
||||
tuple_size::serialize<std::tuple_size<std::tuple<Types...>>>( ar, tuple );
|
||||
tuple_detail::serialize<std::tuple_size<std::tuple<Types...>>::value>::template apply( ar, tuple );
|
||||
}
|
||||
} // namespace cereal
|
||||
|
||||
|
||||
Reference in New Issue
Block a user