From d600f5e11fd8fa6e343aea4162b95eca96e281e3 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Tue, 15 Oct 2024 14:19:00 +0800 Subject: [PATCH 1/2] fix --- iguana/common.hpp | 4 ++-- test/test_pb.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/iguana/common.hpp b/iguana/common.hpp index 2fc6f1f1..236d8fb9 100644 --- a/iguana/common.hpp +++ b/iguana/common.hpp @@ -215,8 +215,8 @@ template inline auto get_pb_members_tuple(T&& t) { using U = ylt::reflection::remove_cvref_t; if constexpr (ylt_refletable_v) { - static auto& offset_arr = ylt::reflection::internal::get_member_offset_arr( - ylt::reflection::internal::wrapper::value); + static auto& offset_arr = + ylt::reflection::internal::get_member_offset_arr(std::forward(t)); using Tuple = decltype(ylt::reflection::object_to_tuple(std::declval())); return build_pb_fields( offset_arr, std::make_index_sequence>{}); diff --git a/test/test_pb.cpp b/test/test_pb.cpp index efa71dfe..c35a2038 100644 --- a/test/test_pb.cpp +++ b/test/test_pb.cpp @@ -765,6 +765,26 @@ TEST_CASE("test members") { val); } +struct some_obj_t { + std::string *name_; + int id_; + + const std::string &name() const { return *name_; } +}; +YLT_REFL(some_obj_t, name(), id_); + +TEST_CASE("mixed method and field") { + std::shared_ptr ptr(new std::string("test")); + some_obj_t obj{ptr.get(), 42}; + std::string str; + iguana::to_pb(obj, str); + CHECK(!str.empty()); + + some_obj_t obj1; + iguana::from_pb(obj1, str); + CHECK(obj.id_ == obj1.id_); +} + struct test_variant { test_variant() = default; test_variant(int a, std::variant b, double c) From 61bbbdcde5a88ed0c993d21f6094adbd71e3b998 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Tue, 15 Oct 2024 14:31:29 +0800 Subject: [PATCH 2/2] update --- test/test_pb.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_pb.cpp b/test/test_pb.cpp index c35a2038..0c57cb44 100644 --- a/test/test_pb.cpp +++ b/test/test_pb.cpp @@ -769,6 +769,7 @@ struct some_obj_t { std::string *name_; int id_; + std::string &name() { return *name_; } const std::string &name() const { return *name_; } }; YLT_REFL(some_obj_t, name(), id_);