11#ifndef MSGPACK_V1_TYPE_VARIANT_HPP
12#define MSGPACK_V1_TYPE_VARIANT_HPP
14#if defined(MSGPACK_USE_STD_VARIANT_ADAPTOR)
18#if MSGPACK_CPP_VERSION >= 201703
34 std::size_t current_index,
35 std::size_t... indices
37Variant construct_variant(
40 std::index_sequence<current_index, indices...>
42 if constexpr(
sizeof...(Ts) == 0) {
43 return Variant{std::in_place_index<current_index>,
object.as<T>()};
46 if (index == current_index) {
47 return Variant{std::in_place_index<current_index>,
object.as<T>()};
49 return construct_variant<Variant, Ts...>(
52 std::index_sequence<indices...>()
57struct object_variant_overload {
63 void operator()(T
const& value) {
72template <
typename... Ts>
73struct as<std::
variant<Ts...>, typename std::enable_if<(msgpack::has_as<Ts>::value && ...)>::type> {
75 if ( o.
type != msgpack::type::ARRAY
82 return detail::construct_variant<std::variant<Ts...>, Ts...>(
85 std::make_index_sequence<
sizeof...(Ts)>()
90template<
typename... Ts>
93 if ( o.
type != msgpack::type::ARRAY
100 v = detail::construct_variant<std::variant<Ts...>, Ts...>(
103 std::make_index_sequence<
sizeof...(Ts)>()
109template <
typename... Ts>
111 template<
typename Stream>
114 std::variant<Ts...>
const& v
118 std::visit([&o](
auto const& value){o.
pack(value);}, v);
124template<
typename... Ts>
125struct object_with_zone<std::
variant<Ts...>> {
128 std::variant<Ts...>
const& v
142 std::visit(detail::object_variant_overload(o.
via.
array.
ptr[1], o.
zone), v);
The class template that supports continuous packing.
Definition pack.hpp:33
packer< Stream > & pack_array(uint32_t n)
Packing array header and size.
Definition pack.hpp:1195
packer< Stream > & pack_uint64(uint64_t d)
Packing uint16.
Definition pack.hpp:740
packer< Stream > & pack(const T &v)
Packing function template.
Definition object_fwd.hpp:231
Definition cpp03_zone.hpp:30
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition cpp03_zone.hpp:255
basic_variant< std::string, std::vector< char >, ext > variant
Definition msgpack_variant.hpp:269
@ ARRAY
Definition object_fwd_decl.hpp:40
Definition adaptor_base.hpp:15
void pack(msgpack::packer< Stream > &o, const T &v)
Definition object.hpp:1185
void convert(T &v, msgpack::object const &o)
Definition object.hpp:1178
msgpack::object const & operator()(msgpack::object const &o, T &v) const
Definition object.hpp:646
void operator()(msgpack::object::with_zone &o, T const &v) const
Definition object.hpp:662
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, T const &v) const
Definition object.hpp:655
msgpack::zone & zone
Definition object.hpp:37
uint32_t size
Definition object_fwd.hpp:23
msgpack::object * ptr
Definition object_fwd.hpp:24
Object class that corresponding to MessagePack format object.
Definition object_fwd.hpp:75
std::enable_if< msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition object.hpp:1126
union_type via
Definition object_fwd.hpp:93
msgpack::type::object_type type
Definition object_fwd.hpp:92
msgpack::object_array array
Definition object_fwd.hpp:85
uint64_t u64
Definition object_fwd.hpp:78
#define MSGPACK_ZONE_ALIGNOF(type)
Definition cpp03_zone_decl.hpp:30
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66