You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case this is useful to anyone in future, I worked out how to do this. Helpfully, much of the magic_enum reflection is constexpr, so can be used with templates - the only tricky bit is to convert an enum entry list into a sequence of rttr::value arguments for the registration call. I've not had to go this deep on template metaprogramming before, so this code might not be very polished, but it does seem to work. You can just call RegisterMagicEnum<MyEnum>() within RTTR_REGISTRATION to register your enum.
// Given an array of magic_enum entries, registers these as an RTTR enumeration.// This is done by also receiving an index sequence whose length matches// the length of the array. Template parameter pack expansion is used to// expand the number of rttr::value arguments passed to the enumeration// registration function.template<typename EnumType, size_t ArraySize, std::size_t... Indices>
staticvoidRegisterMagicEnumHelper(
std::array<std::pair<EnumType, std::string_view>, ArraySize> enumEntries,
std::index_sequence<Indices...>
) noexcept
{
rttr::registration::enumeration<EnumType>(magic_enum::enum_type_name<EnumType>().data())(
rttr::value(
rttr::string_view(std::get<Indices>(enumEntries).second.data()),
std::get<Indices>(enumEntries).first
)...
);
}
template<typename EnumType>
staticvoidRegisterMagicEnum() noexcept
{
constexpr std::size_t NUM_ENUM_ENTRIES = magic_enum::enum_count<EnumType>();
RegisterMagicEnumHelper<EnumType, NUM_ENUM_ENTRIES>(
magic_enum::enum_entries<EnumType>(),
std::make_index_sequence<NUM_ENUM_ENTRIES> {}
);
}
No description provided.
The text was updated successfully, but these errors were encountered: