30#ifndef CEREAL_TYPES_STD_VARIANT_HPP_
31#define CEREAL_TYPES_STD_VARIANT_HPP_
39 namespace variant_detail
42 template <
class Archive>
48 void operator()(T
const & value)
const
57 template<
int N,
class Variant,
class Archive>
58 typename std::enable_if<N == std::variant_size_v<Variant>,
void>::type
59 load_variant(Archive & ,
int , Variant & )
61 throw ::cereal::Exception(
"Error traversing variant during load");
64 template<
int N,
class Variant,
class Archive>
65 typename std::enable_if<N < std::variant_size_v<Variant>,
void>::type
66 load_variant(Archive & ar,
int target, Variant & variant)
70 variant.template emplace<N>();
74 load_variant<N+1>(ar, target, variant);
80 template <
class Archive,
typename VariantType1,
typename... VariantTypes>
inline
83 std::int32_t index =
static_cast<std::int32_t
>(variant.index());
86 std::visit(visitor, variant);
90 template <
class Archive,
typename... VariantTypes>
inline
93 using variant_t =
typename std::variant<VariantTypes...>;
97 if(index >=
static_cast<std::int32_t
>(std::variant_size_v<variant_t>))
98 throw Exception(
"Invalid 'index' selector when deserializing std::variant");
100 variant_detail::load_variant<0>(ar, index, variant);
104 template <
class Archive>
Main cereal functionality.
#define CEREAL_NVP_(name, value)
Convenience for creating a templated NVP.
Definition: helpers.hpp:201
#define CEREAL_LOAD_FUNCTION_NAME
The deserialization (load) function name to search for.
Definition: macros.hpp:85
#define CEREAL_SAVE_FUNCTION_NAME
The serialization (save) function name to search for.
Definition: macros.hpp:92
#define CEREAL_SERIALIZE_FUNCTION_NAME
The serialization/deserialization function name to search for.
Definition: macros.hpp:78
An exception class thrown when things go wrong at runtime.
Definition: helpers.hpp:49
Definition: variant.hpp:44