From f914a185c38d344f306e68035589f377af55c21c Mon Sep 17 00:00:00 2001 From: Samuel Debionne Date: Mon, 11 Mar 2019 17:37:51 +0100 Subject: [PATCH 001/108] Add support for std::variant --- CMake/CMakeLists.txt | 1 + doc/serialization.html | 1 + include/boost/serialization/std_variant.hpp | 199 +++++++++++++++ test/Jamfile.v2 | 1 + test/test_std_variant.cpp | 256 ++++++++++++++++++++ 5 files changed, 458 insertions(+) create mode 100644 include/boost/serialization/std_variant.hpp create mode 100644 test/test_std_variant.cpp diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt index 00868f853f..005acd634e 100644 --- a/CMake/CMakeLists.txt +++ b/CMake/CMakeLists.txt @@ -360,6 +360,7 @@ archive_test(test_unregistered) archive_test(test_unique_ptr) archive_test(test_valarray) archive_test(test_variant A) +archive_test(test_std_variant A) archive_test(test_vector A) archive_test(test_set A) archive_test(test_set_boost_unordered A) diff --git a/doc/serialization.html b/doc/serialization.html index 8252930986..379403cd55 100644 --- a/doc/serialization.html +++ b/doc/serialization.html @@ -919,6 +919,7 @@

Models - Serialization Implementations Included in the
  • shared_ptr
  • auto_ptr (demo) +C++17 std::variant is supported as well. Others are being added to the list so check the boost files section and headers for new implementations!
    diff --git a/include/boost/serialization/std_variant.hpp b/include/boost/serialization/std_variant.hpp new file mode 100644 index 0000000000..37c3041c58 --- /dev/null +++ b/include/boost/serialization/std_variant.hpp @@ -0,0 +1,199 @@ +#ifndef BOOST_SERIALIZATION_STD_VARIANT_HPP +#define BOOST_SERIALIZATION_STD_VARIANT_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// variant.hpp - non-intrusive serialization of variant types +// +// copyright (c) 2019 Samuel Debionne, ESRF +// +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org for updates, documentation, and revision history. +// +// Widely inspired form boost::variant serialization +// + +#include + +#include + +#include + +#include +#include +#include + +namespace boost { +namespace serialization { + +template +struct variant_save_visitor +{ + variant_save_visitor(Archive& ar) : + m_ar(ar) + {} + template + void operator()(T const & value) const + { + m_ar << BOOST_SERIALIZATION_NVP(value); + } +private: + Archive & m_ar; +}; + + +template +struct variant_load_visitor +{ + variant_load_visitor(Archive& ar) : + m_ar(ar) + {} + template + void operator()(T & value) const + { + m_ar >> BOOST_SERIALIZATION_NVP(value); + } +private: + Archive & m_ar; +}; + +template +void save( + Archive & ar, + std::variant const & v, + unsigned int /*version*/ +){ + const std::size_t which = v.index(); + ar << BOOST_SERIALIZATION_NVP(which); + variant_save_visitor visitor(ar); + std::visit(visitor, v); +} + +// Minimalist metaprogramming for handling parameter pack +namespace mp { + namespace detail { + template + struct front_impl; + + template