Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Oct 15, 2024
1 parent 095f27c commit d600f5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions iguana/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ template <typename T>
inline auto get_pb_members_tuple(T&& t) {
using U = ylt::reflection::remove_cvref_t<T>;
if constexpr (ylt_refletable_v<U>) {
static auto& offset_arr = ylt::reflection::internal::get_member_offset_arr(
ylt::reflection::internal::wrapper<U>::value);
static auto& offset_arr =
ylt::reflection::internal::get_member_offset_arr(std::forward<T>(t));
using Tuple = decltype(ylt::reflection::object_to_tuple(std::declval<U>()));
return build_pb_fields<Tuple, T>(
offset_arr, std::make_index_sequence<std::tuple_size_v<Tuple>>{});
Expand Down
20 changes: 20 additions & 0 deletions test/test_pb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<double, std::string, int> b, double c)
Expand Down

0 comments on commit d600f5e

Please sign in to comment.