Skip to content

Commit

Permalink
fix msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jul 31, 2023
1 parent 28775dc commit 2e37609
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
10 changes: 9 additions & 1 deletion include/ylt/struct_pack/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ namespace detail {
if constexpr (user_defined_refl<type>) {
return decltype(STRUCT_PACK_FIELD_COUNT(std::declval<type>()))::value;
}
if constexpr (tuple_size<type>) {
else if constexpr (tuple_size<type>) {
return std::tuple_size<type>::value;
}
else {
Expand All @@ -760,6 +760,14 @@ namespace detail {

constexpr static auto MaxVisitMembers = 64;

template<typename Object,typename Visitor>
constexpr decltype(auto) STRUCT_PACK_INLINE visit_members_by_user_defined_refl(Object &&object,
Visitor &&visitor);

template<typename Object,typename Visitor>
constexpr decltype(auto) STRUCT_PACK_INLINE visit_members_by_structure_binding(Object &&object,
Visitor &&visitor);

template<typename Object,typename Visitor>
constexpr decltype(auto) STRUCT_PACK_INLINE visit_members(Object &&object,
Visitor &&visitor) {
Expand Down
40 changes: 24 additions & 16 deletions include/ylt/struct_pack/struct_pack_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ constexpr size_info inline calculate_one_size(const T &item) {
static_assert(id != detail::type_id::type_end_flag);
using type = remove_cvref_t<decltype(item)>;
static_assert(!std::is_pointer_v<type>);
size_info ret{.total = 0, .size_cnt = 0, .max_size = 0};
size_info ret{};
if constexpr (id == type_id::monostate_t) {
}
else if constexpr (std::is_fundamental_v<type> || std::is_enum_v<type> ||
Expand Down Expand Up @@ -2476,16 +2476,6 @@ class unpacker {
}
}

template <typename U>
auto get_container_value_t(const U &) {
if constexpr (map_container<U>) {
return std::pair<typename U::key_type, typename U::mapped_type>{};
}
else {
return typename U::value_type{};
}
};

template <size_t size_type, uint64_t version, bool NotSkip, typename T>
constexpr struct_pack::errc inline deserialize_one(T &item) {
struct_pack::errc code{};
Expand Down Expand Up @@ -2595,11 +2585,29 @@ class unpacker {
if SP_UNLIKELY (size == 0) {
return {};
}
if constexpr (map_container<type> || set_container<type>) {
// value is the element of map/set container.
// if the type is set, then value is set::value_type;
// if the type is map, then value is pair<key_type,mapped_type>
decltype(get_container_value_t(item)) value;
if constexpr (map_container<type>) {
std::pair<typename type::key_type, typename type::mapped_type>
value{};
if constexpr (is_trivial_serializable<decltype(value)>::value &&
!NotSkip) {
return reader_.ignore(size * sizeof(value)) ? errc{}
: errc::no_buffer_space;
}
else {
for (size_t i = 0; i < size; ++i) {
code = deserialize_one<size_type, version, NotSkip>(value);
if SP_UNLIKELY (code != struct_pack::errc{}) {
return code;
}
if constexpr (NotSkip) {
item.emplace(std::move(value));
// TODO: mapped_type can deserialize without be moved
}
}
}
}
else if constexpr (set_container<type>) {
typename type::value_type value{};
if constexpr (is_trivial_serializable<decltype(value)>::value &&
!NotSkip) {
return reader_.ignore(size * sizeof(value)) ? errc{}
Expand Down

0 comments on commit 2e37609

Please sign in to comment.