From ea977aa33f0f4d345a8176622036db71aaf09261 Mon Sep 17 00:00:00 2001 From: saipubw Date: Mon, 25 Sep 2023 14:14:12 +0800 Subject: [PATCH] [struct_pack] fix marco warning (#466) --- include/ylt/struct_pack/calculate_size.hpp | 15 ++++++--------- include/ylt/struct_pack/derived_marco.hpp | 2 +- include/ylt/struct_pack/foreach_macro.h | 3 ++- include/ylt/struct_pack/unpacker.hpp | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/ylt/struct_pack/calculate_size.hpp b/include/ylt/struct_pack/calculate_size.hpp index d959a2cc5..664970d34 100644 --- a/include/ylt/struct_pack/calculate_size.hpp +++ b/include/ylt/struct_pack/calculate_size.hpp @@ -28,9 +28,9 @@ namespace struct_pack { struct serialize_buffer_size; namespace detail { -template +template constexpr size_info STRUCT_PACK_INLINE -calculate_payload_size(const T &item, const Args &...items); +calculate_payload_size(const Args &...items); template constexpr size_info inline calculate_one_size(const T &item) { @@ -64,7 +64,7 @@ constexpr size_info inline calculate_one_size(const T &item) { } else if constexpr (container) { ret.size_cnt += 1; - ret.max_size = (std::max)(ret.max_size, item.size()); + ret.max_size = item.size(); if constexpr (trivially_copyable_container) { using value_type = typename type::value_type; ret.total = item.size() * sizeof(value_type); @@ -158,13 +158,10 @@ constexpr size_info inline calculate_one_size(const T &item) { return ret; } -template +template 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 STRUCT_PACK_INLINE constexpr serialize_buffer_size get_serialize_runtime_info( diff --git a/include/ylt/struct_pack/derived_marco.hpp b/include/ylt/struct_pack/derived_marco.hpp index 28951a286..063f584d5 100644 --- a/include/ylt/struct_pack/derived_marco.hpp +++ b/include/ylt/struct_pack/derived_marco.hpp @@ -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__) diff --git a/include/ylt/struct_pack/foreach_macro.h b/include/ylt/struct_pack/foreach_macro.h index 764bf51f6..87ba6dc04 100644 --- a/include/ylt/struct_pack/foreach_macro.h +++ b/include/ylt/struct_pack/foreach_macro.h @@ -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__) \ No newline at end of file + STRUCT_PACK_EXPAND_EACH_(sepatator,fun,__VA_ARGS__) + \ No newline at end of file diff --git a/include/ylt/struct_pack/unpacker.hpp b/include/ylt/struct_pack/unpacker.hpp index 114acdc88..83adebbbe 100644 --- a/include/ylt/struct_pack/unpacker.hpp +++ b/include/ylt/struct_pack/unpacker.hpp @@ -600,7 +600,7 @@ class unpacker { bool ok; auto index = search_type_by_md5(id, ok); if SP_UNLIKELY (!ok) { - return {}; + return errc::invalid_buffer; } else { return template_switch