30 #ifndef CEREAL_TYPES_BOOST_VARIANT_HPP_
31 #define CEREAL_TYPES_BOOST_VARIANT_HPP_
34 #if defined(_MSC_VER) && _MSC_VER < 1911
35 #define CEREAL_CONSTEXPR_LAMBDA
36 #else // MSVC 2017 or newer, all other compilers
37 #define CEREAL_CONSTEXPR_LAMBDA constexpr
41 #include <boost/variant/variant_fwd.hpp>
42 #include <boost/variant/static_visitor.hpp>
46 namespace boost_variant_detail
49 template <
class Archive>
55 void operator()(T
const & value)
const
64 template <
class Archive,
class T>
67 using ST =
typename std::aligned_storage<
sizeof(T),
CEREAL_ALIGNOF(T)>::type;
81 void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar )
98 template <
class Variant,
class Archive>
99 static void load_variant( Archive &, Variant & )
108 template <
class Archive,
class Variant>
109 static void load_variant_impl( Archive & ar, Variant & variant, std::true_type )
113 variant = std::move(value);
117 template<
class Variant,
class Archive>
118 static void load_variant_impl(Archive & ar, Variant & variant, std::false_type )
120 LoadAndConstructLoadWrapper<Archive, T> loadWrapper;
123 variant = std::move(*loadWrapper.construct.ptr());
127 template<
class Variant,
class Archive>
128 static void load_variant(Archive & ar, Variant & variant)
130 load_variant_impl( ar, variant,
typename std::is_default_constructible<T>::type() );
136 template <
class Archive,
typename ... VariantTypes>
inline
139 int32_t which = variant.which();
142 variant.apply_visitor(visitor);
146 template <
class Archive,
typename ... VariantTypes>
inline
152 using LoadFuncType = void(*)(Archive &, boost::variant<VariantTypes...> &);
155 if(which >= int32_t(
sizeof(loadFuncArray)/
sizeof(loadFuncArray[0])))
156 throw Exception(
"Invalid 'which' selector when deserializing boost::variant");
158 loadFuncArray[which](ar, variant);
162 #undef CEREAL_CONSTEXPR_LAMBDA
164 #endif // CEREAL_TYPES_BOOST_VARIANT_HPP_