diff --git a/iguana/ylt/reflection/member_value.hpp b/iguana/ylt/reflection/member_value.hpp index dbdafbab..47d09246 100644 --- a/iguana/ylt/reflection/member_value.hpp +++ b/iguana/ylt/reflection/member_value.hpp @@ -176,6 +176,13 @@ inline size_t index_of(T& t, Field& value) { return std::distance(offset_arr.begin(), it); } +template +inline size_t index_of(Member member) { + using T = typename member_traits::owner_type; + static auto& t = internal::get_fake_object(); + return index_of(t, t.*member); +} + template inline constexpr std::string_view name_of(T& t, Field& value) { size_t index = index_of(t, value); diff --git a/test/test_reflection.cpp b/test/test_reflection.cpp index 2cd64fe6..78d13e36 100644 --- a/test/test_reflection.cpp +++ b/test/test_reflection.cpp @@ -374,6 +374,11 @@ TEST_CASE("test macros") { constexpr auto idx2 = index_of<&simple2::id>(); static_assert(idx2 == 1); + auto i = index_of(&simple::id); + CHECK(i == 1); + i = index_of(&simple::age); + CHECK(i == 3); + constexpr auto arr = get_member_names(); static_assert(arr.size() == 4); constexpr auto map = member_names_map;