Skip to content

Commit

Permalink
[struct_pack] fix marco warning (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle authored Sep 25, 2023
1 parent d32b0ee commit ea977aa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
15 changes: 6 additions & 9 deletions include/ylt/struct_pack/calculate_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace struct_pack {

struct serialize_buffer_size;
namespace detail {
template <typename T, typename... Args>
template <typename... Args>
constexpr size_info STRUCT_PACK_INLINE
calculate_payload_size(const T &item, const Args &...items);
calculate_payload_size(const Args &...items);

template <typename T>
constexpr size_info inline calculate_one_size(const T &item) {
Expand Down Expand Up @@ -64,7 +64,7 @@ constexpr size_info inline calculate_one_size(const T &item) {
}
else if constexpr (container<type>) {
ret.size_cnt += 1;
ret.max_size = (std::max)(ret.max_size, item.size());
ret.max_size = item.size();
if constexpr (trivially_copyable_container<type>) {
using value_type = typename type::value_type;
ret.total = item.size() * sizeof(value_type);
Expand Down Expand Up @@ -158,13 +158,10 @@ constexpr size_info inline calculate_one_size(const T &item) {
return ret;
}

template <typename T, typename... Args>
template <typename... Args>
constexpr size_info STRUCT_PACK_INLINE
calculate_payload_size(const T &item, const Args &...items) {
if constexpr (sizeof...(items) != 0)
return calculate_one_size(item) + calculate_payload_size(items...);
else
return calculate_one_size(item);
calculate_payload_size(const Args &...items) {
return (calculate_one_size(items) + ...);
}
template <uint64_t conf, typename... Args>
STRUCT_PACK_INLINE constexpr serialize_buffer_size get_serialize_runtime_info(
Expand Down
2 changes: 1 addition & 1 deletion include/ylt/struct_pack/derived_marco.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
#define STRUCT_PACK_DERIVED_DECL(base, ...) \
STRUCT_PACK_EXPAND_EACH(, GET_STRUCT_PACK_ID_IMPL_FOR_LOOP, base, \
__VA_ARGS__) \
STRUCT_PACK_DERIVED_IMPL(base, __VA_ARGS__)\
STRUCT_PACK_DERIVED_IMPL(base, __VA_ARGS__)
3 changes: 2 additions & 1 deletion include/ylt/struct_pack/foreach_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,5 @@
#define STRUCT_PACK_EXPAND_EACH_(sepatator,fun,...) \
STRUCT_PACK_MARCO_EXPAND(STRUCT_PACK_CONCAT(STRUCT_PACK_DOARG,STRUCT_PACK_ARG_COUNT(__VA_ARGS__))(sepatator,fun,__VA_ARGS__))
#define STRUCT_PACK_EXPAND_EACH(sepatator,fun,...) \
STRUCT_PACK_EXPAND_EACH_(sepatator,fun,__VA_ARGS__)
STRUCT_PACK_EXPAND_EACH_(sepatator,fun,__VA_ARGS__)

2 changes: 1 addition & 1 deletion include/ylt/struct_pack/unpacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ class unpacker {
bool ok;
auto index = search_type_by_md5<typename type::element_type>(id, ok);
if SP_UNLIKELY (!ok) {
return {};
return errc::invalid_buffer;
}
else {
return template_switch<deserialize_one_derived_class_helper<
Expand Down

0 comments on commit ea977aa

Please sign in to comment.