14

Does boost support serialization of c++11's std::tuple?

I couldn't find a tuple.hpp header file at /boost/serialization/

I'm using boost 1.52.0 (happy to upgrade if need be, but it seems like the changes in version 1.53 doesn't have anything related to this).

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Ammar
  • 573
  • 1
  • 4
  • 14

3 Answers3

8

Out of the box, no. You'll have to write the serializer yourself. Luckily, someone already did:

C++0x tuple boost serialization (also in github)

eladidan
  • 2,634
  • 2
  • 26
  • 39
1

Using C++17's fold expressions, you can easily implement a serializer:

template <typename Archive, typename... Types>
void boost::serialization::serialize(Archive &ar, std::tuple<Types...> &t, const unsigned int)
{
    std::apply([&](auto &...element)
                { ((ar & element), ...); },
                t);
}

Based on this answer.

LHLaurini
  • 1,737
  • 17
  • 31