Skip to content

Commit

Permalink
Add preliminary support for generic serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebionne committed Jun 4, 2019
1 parent 84e9ab5 commit 593724f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions include/boost/serialization/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <boost/config.hpp>
#include <boost/serialization/strong_typedef.hpp>

if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
#include <type_traits> // For std::is_same, std::enable_if
#endif

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// serialization.hpp: interface for serialization system.

Expand Down Expand Up @@ -60,6 +64,44 @@ namespace serialization {

BOOST_STRONG_TYPEDEF(unsigned int, version_type)

#if __cplusplus==201103L

namespace detail {

struct has_serialize
{

private:
template<class T>
static constexpr auto check(T*)
-> typename
std::is_same<
decltype(std::declval<T>().serialize(std::declval<Archive&>(), std::declval<unsigned int>())),
void
>::type;

template<class>
static constexpr std::false_type check(...);

typedef decltype(check<C>(0)) type;

public:
static constexpr bool value = type::value;
};

} //namespace detail

// default implementation - call the member function "serialize" if it exists,
// else removed from overload resolution.
template<class Archive, class T>
inline typename std::enable_if<detail::has_serialize<Archive, T>::value>::type serialize(
Archive & ar, T & t, const unsigned int file_version
){
access::serialize(ar, t, static_cast<unsigned int>(file_version));
}

#else //__cplusplus==201103L

// default implementation - call the member function "serialize"
template<class Archive, class T>
inline void serialize(
Expand All @@ -68,6 +110,8 @@ inline void serialize(
access::serialize(ar, t, static_cast<unsigned int>(file_version));
}

#endif //__cplusplus==201103L

// save data required for construction
template<class Archive, class T>
inline void save_construct_data(
Expand Down

0 comments on commit 593724f

Please sign in to comment.