Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preliminary support for generic serialization #160

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need <type_traits>, versions of enable_if and is_same are in boost.core.

#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
Copy link
Contributor

@HDembinski HDembinski Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use detection from boost.config instead of raw checks like this.


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>())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is Archive& coming from here?

void
>::type;

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

typedef decltype(check<C>(0)) type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Boost.Concept should be used instead of writing this manually.


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