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>
108 #endif // CEREAL_TYPES_STD_VARIANT_HPP_