diff --git a/include/ylt/thirdparty/iguana/json_writer.hpp b/include/ylt/thirdparty/iguana/json_writer.hpp index 64758ece2..d8cad6fe0 100644 --- a/include/ylt/thirdparty/iguana/json_writer.hpp +++ b/include/ylt/thirdparty/iguana/json_writer.hpp @@ -242,7 +242,7 @@ IGUANA_INLINE void to_json(T &&t, Stream &s) { s.push_back('{'); for_each(std::forward(t), [&t, &s](const auto &v, auto i) IGUANA__INLINE_LAMBDA { - using M = decltype(iguana_reflect_members(std::forward(t))); + using M = decltype(iguana_reflect_type(std::forward(t))); constexpr auto Idx = decltype(i)::value; constexpr auto Count = M::value(); static_assert(Idx < Count); diff --git a/include/ylt/thirdparty/iguana/reflection.hpp b/include/ylt/thirdparty/iguana/reflection.hpp index ee626f307..85f9020e6 100644 --- a/include/ylt/thirdparty/iguana/reflection.hpp +++ b/include/ylt/thirdparty/iguana/reflection.hpp @@ -552,7 +552,8 @@ namespace iguana::detail { MACRO_CONCAT(CON_STR, GET_ARG_COUNT(__VA_ARGS__))(__VA_ARGS__) #define MAKE_META_DATA_IMPL(STRUCT_NAME, ...) \ - inline auto iguana_reflect_members(STRUCT_NAME const &) { \ + [[maybe_unused]] inline static auto iguana_reflect_members( \ + STRUCT_NAME const &) { \ struct reflect_members { \ constexpr decltype(auto) static apply_impl() { \ return std::make_tuple(__VA_ARGS__); \ @@ -574,13 +575,13 @@ namespace iguana::detail { return reflect_members{}; \ } -#define MAKE_META_DATA(STRUCT_NAME, TABLE_NAME, N, ...) \ - constexpr inline std::array arr_##STRUCT_NAME = { \ - MARCO_EXPAND(MACRO_CONCAT(CON_STR, N)(__VA_ARGS__))}; \ - constexpr inline std::string_view fields_##STRUCT_NAME = { \ - MAKE_NAMES(__VA_ARGS__)}; \ - constexpr inline std::string_view name_##STRUCT_NAME = TABLE_NAME; \ - MAKE_META_DATA_IMPL(STRUCT_NAME, \ +#define MAKE_META_DATA(STRUCT_NAME, TABLE_NAME, N, ...) \ + static constexpr inline std::array arr_##STRUCT_NAME = { \ + MARCO_EXPAND(MACRO_CONCAT(CON_STR, N)(__VA_ARGS__))}; \ + static constexpr inline std::string_view fields_##STRUCT_NAME = { \ + MAKE_NAMES(__VA_ARGS__)}; \ + static constexpr inline std::string_view name_##STRUCT_NAME = TABLE_NAME; \ + MAKE_META_DATA_IMPL(STRUCT_NAME, \ MAKE_ARG_LIST(N, &STRUCT_NAME::FIELD, __VA_ARGS__)) #define MAKE_META_DATA_IMPL_EMPTY(STRUCT_NAME) \ @@ -634,13 +635,16 @@ namespace iguana { MAKE_META_DATA(STRUCT_NAME, TABLE_NAME, GET_ARG_COUNT(__VA_ARGS__), \ __VA_ARGS__) +template +inline auto iguana_reflect_type(const T &t); + inline std::unordered_map< std::string_view, std::vector>> g_iguana_custom_map; template inline constexpr auto get_iguana_struct_map() { - using reflect_members = decltype(iguana_reflect_members(std::declval())); + using reflect_members = decltype(iguana_reflect_type(std::declval())); if constexpr (reflect_members::value() == 0) { return std::array{}; } @@ -732,13 +736,49 @@ inline int add_custom_fields(std::string_view key, template using Reflect_members = decltype(iguana_reflect_members(std::declval())); +template +struct is_public_reflection : std::false_type {}; + +template +struct is_public_reflection< + T, std::void_t()))>> + : std::true_type {}; + +template +constexpr bool is_public_reflection_v = is_public_reflection::value; + +template +struct is_private_reflection : std::false_type {}; + +template +struct is_private_reflection< + T, std::void_t().iguana_reflect_members( + std::declval()))>> : std::true_type {}; + +template +constexpr bool is_private_reflection_v = is_private_reflection::value; + template struct is_reflection : std::false_type {}; template -struct is_reflection::arr())>> +struct is_reflection>> + : std::true_type {}; + +template +struct is_reflection>> : std::true_type {}; +template +inline auto iguana_reflect_type(const T &t) { + if constexpr (is_public_reflection_v) { + return iguana_reflect_members(t); + } + else { + return t.iguana_reflect_members(t); + } +} + template inline constexpr bool is_reflection_v = is_reflection::value; @@ -761,14 +801,14 @@ constexpr int element_index_helper() { template