Skip to content

Commit

Permalink
[struct_pack][bugfix] add inline keyword for STRUCT_PACK_REFL helper …
Browse files Browse the repository at this point in the history
…function (#446)
  • Loading branch information
poor-circle authored Sep 6, 2023
1 parent d16f0d6 commit 10e7e63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions include/ylt/struct_pack/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,22 +2208,22 @@ if constexpr (Idx == I) {\
}\

#define STRUCT_PACK_GET_INDEX(Idx, Type) \
auto& STRUCT_PACK_GET_##Idx(Type& c) {\
inline auto& STRUCT_PACK_GET_##Idx(Type& c) {\
return STRUCT_PACK_GET<STRUCT_PACK_FIELD_COUNT_IMPL<Type>()-1-Idx>(c);\
}\

#define STRUCT_PACK_GET_INDEX_CONST(Idx, Type) \
const auto& STRUCT_PACK_GET_##Idx(const Type& c) {\
inline const auto& STRUCT_PACK_GET_##Idx(const Type& c) {\
return STRUCT_PACK_GET<STRUCT_PACK_FIELD_COUNT_IMPL<Type>()-1-Idx>(c);\
}\

#define STRUCT_PACK_REFL(Type,...) \
Type& STRUCT_PACK_REFL_FLAG(Type& t) {return t;} \
inline Type& STRUCT_PACK_REFL_FLAG(Type& t) {return t;} \
template<typename T> \
constexpr std::size_t STRUCT_PACK_FIELD_COUNT_IMPL(); \
template<> \
constexpr std::size_t STRUCT_PACK_FIELD_COUNT_IMPL<Type>() {return STRUCT_PACK_ARG_COUNT(__VA_ARGS__);} \
decltype(auto) STRUCT_PACK_FIELD_COUNT(const Type &){ \
inline decltype(auto) STRUCT_PACK_FIELD_COUNT(const Type &){ \
return std::integral_constant<std::size_t,STRUCT_PACK_ARG_COUNT(__VA_ARGS__)>{}; \
} \
template<std::size_t I> auto& STRUCT_PACK_GET(Type& c) { \
Expand Down
8 changes: 7 additions & 1 deletion src/struct_pack/tests/test_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ struct my_tree {
((a.right_child != nullptr && b.right_child != nullptr) &&
*a.right_child == *b.right_child));
}
};
};

struct person_with_refl {
std::string name;
int age;
};
STRUCT_PACK_REFL(person_with_refl, name, age);

0 comments on commit 10e7e63

Please sign in to comment.