mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 23:07:58 +02:00
fix style
This commit is contained in:
@@ -32,11 +32,13 @@ template <
|
|||||||
typename T,
|
typename T,
|
||||||
typename... Ts,
|
typename... Ts,
|
||||||
std::size_t current_index,
|
std::size_t current_index,
|
||||||
std::size_t... indices>
|
std::size_t... indices
|
||||||
|
>
|
||||||
Variant construct_variant(
|
Variant construct_variant(
|
||||||
std::size_t index,
|
std::size_t index,
|
||||||
msgpack::object& object,
|
msgpack::object& object,
|
||||||
std::index_sequence<current_index, indices...>) {
|
std::index_sequence<current_index, indices...>
|
||||||
|
) {
|
||||||
if constexpr(sizeof...(Ts) == 0) {
|
if constexpr(sizeof...(Ts) == 0) {
|
||||||
return object.as<T>();
|
return object.as<T>();
|
||||||
}
|
}
|
||||||
@@ -47,7 +49,8 @@ Variant construct_variant(
|
|||||||
return construct_variant<Variant, Ts...>(
|
return construct_variant<Variant, Ts...>(
|
||||||
index,
|
index,
|
||||||
object,
|
object,
|
||||||
std::index_sequence<indices...>());
|
std::index_sequence<indices...>()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +109,10 @@ struct convert<std::variant<Ts...>> {
|
|||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
struct pack<std::variant<Ts...>>{
|
struct pack<std::variant<Ts...>>{
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, std::variant<Ts...> const& v) const {
|
msgpack::packer<Stream>& operator()(
|
||||||
|
msgpack::packer<Stream>& o,
|
||||||
|
std::variant<Ts...> const& v
|
||||||
|
) const {
|
||||||
o.pack_array(2);
|
o.pack_array(2);
|
||||||
o.pack_uint64(v.index());
|
o.pack_uint64(v.index());
|
||||||
std::visit([&o](auto const& value){o.pack(value);}, v);
|
std::visit([&o](auto const& value){o.pack(value);}, v);
|
||||||
@@ -117,10 +123,17 @@ struct pack<std::variant<Ts...>>{
|
|||||||
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct object_with_zone<std::variant<Ts...>> {
|
struct object_with_zone<std::variant<Ts...>> {
|
||||||
void operator()(msgpack::object::with_zone& o, std::variant<Ts...> const& v) const {
|
void operator()(
|
||||||
msgpack::object *p = static_cast<msgpack::object *>(
|
msgpack::object::with_zone& o,
|
||||||
o.zone.allocate_align(sizeof(msgpack::object) * 2,
|
std::variant<Ts...> const& v
|
||||||
MSGPACK_ZONE_ALIGNOF(msgpack::object)));
|
) const {
|
||||||
|
msgpack::object *p =
|
||||||
|
static_cast<msgpack::object *>(
|
||||||
|
o.zone.allocate_align(
|
||||||
|
sizeof(msgpack::object) * 2,
|
||||||
|
MSGPACK_ZONE_ALIGNOF(msgpack::object)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
o.via.array.size = 2;
|
o.via.array.size = 2;
|
||||||
|
@@ -470,7 +470,8 @@ BOOST_AUTO_TEST_CASE(variant_pack_unpack_as) {
|
|||||||
std::string const& str = ss.str();
|
std::string const& str = ss.str();
|
||||||
msgpack::object_handle oh =
|
msgpack::object_handle oh =
|
||||||
msgpack::unpack(str.data(), str.size());
|
msgpack::unpack(str.data(), str.size());
|
||||||
std::variant<bool, int, float, double> val2 = oh.get().as<std::variant<bool, int, float, double> >();
|
std::variant<bool, int, float, double> val2 =
|
||||||
|
oh.get().as<std::variant<bool, int, float, double> >();
|
||||||
BOOST_CHECK(val1 == val2);
|
BOOST_CHECK(val1 == val2);
|
||||||
BOOST_CHECK_THROW((oh.get().as<std::variant<bool>>()), msgpack::type_error);
|
BOOST_CHECK_THROW((oh.get().as<std::variant<bool>>()), msgpack::type_error);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user