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

Conversation

sdebionne
Copy link
Contributor

@sdebionne sdebionne commented Jun 4, 2019

See #113 for the rationale.

One possible use case is generic support for Boost.Hana Structs that have some level of reflection:

#include <type_traits>

#include <boost/hana/fwd/define_struct.hpp>
#include <boost/hana/fwd/for_each.hpp>
#include <boost/hana/fwd/second.hpp>

namespace boost {
    namespace serialization {

/// Template specialization for Boost.Hana structures
template <typename Archive, typename T>
std::enable_if_t<hana::Struct<T>::value> serialize(Archive& ar, T& d, const unsigned int version)
{
    hana::for_each(d, [&ar](auto member) { ar & hana::second(member); });
}

    } // namespace serialization
} // namespace boost

Let me know if there is a better way to properly test for std=c++11 and the availability of <type_traits>.

Is there any other place in the library where functionalities are conditionally supported given a c++ standard level?

@sdebionne sdebionne force-pushed the add-generic-serialization-support branch from 593724f to 3e071dd Compare June 4, 2019 16:13
@sdebionne
Copy link
Contributor Author

@HDembinski @robertramey Any chance that you guys find time to review this PR? If accepted, it would be great to have in 1.71...

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?

@@ -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.

@@ -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.

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.

@HDembinski
Copy link
Contributor

I am not the maintainer of this library, but here is a review.

@HDembinski
Copy link
Contributor

The whole check can be implemented in pre-C++11 code, I think. https://stackoverflow.com/questions/257288/is-it-possible-to-write-a-template-to-check-for-a-functions-existence

@robertramey
Copy link
Member

Let me know if there is a better way to properly test for std=c++11 and the availability of <type_traits>.

Take serious look at Boost config. It has been the cornerstone of boost serialization portability. People take boost serialization portability for granted, but it's in fact an incredible feat which is totally due to the efforts of John Maddock's Boost config. I never test for any specific C++ version - only the existence of a capability as specified by boost config. It has to be this way because compilers which purport to support C++11 are not all in sync which combination of C++11 features they support. The fact is that there is no defacto C++ standard - only a theoretical one.

Is there any other place in the library where functionalities are conditionally supported given a c++ standard level?

easy. look through the bjam test files and the tests themselves.

@HDembinski
Copy link
Contributor

@robertramey I share your admiration of boost.config :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants