Add get typelist for tag

This commit is contained in:
sha512sum 2024-04-18 01:17:58 +00:00
parent b802725e11
commit dfd8a788f8

View file

@ -21,7 +21,6 @@ struct MetaInfo {
using Type = T;
private:
static constexpr auto _ = loopholes::Injector<MetaInfoKey<kTypeId, Tag>{}, TypeList<T>{}>{};
};
template <typename T, typename Tag = impl::Types>
@ -33,4 +32,37 @@ using GetMetaInfo = MetaInfo<typename decltype(Magic(loopholes::Getter<MetaInfoK
template <std::size_t Id, typename Tag = impl::Types>
using GetType = GetMetaInfo<Id, Tag>::Type;
namespace impl {
template <typename Tag, std::size_t I = 0, typename... Ts, typename G>
static consteval auto GetTypeListForTag(G g) requires (I == 0 ||
requires {Magic(loopholes::Getter<MetaInfoKey<I, Tag>{}>{});}) {
if constexpr(I == 0 && !requires {Magic(loopholes::Getter<MetaInfoKey<I, Tag>{}>{});}) {
return TypeList{};
} else {
if constexpr(requires{GetTypeListForTag<Tag, I + 1, Ts...>(g);}) {
constexpr auto type = Magic(loopholes::Getter<MetaInfoKey<I, Tag>{}>{});
return GetTypeListForTag<Tag, I + 1, Ts..., typename decltype(type)::Type>(g);
} else {
constexpr auto type = Magic(loopholes::Getter<MetaInfoKey<I, Tag>{}>{});
return TypeList<Ts..., typename decltype(type)::Type>();
};
};
};
} // namespace impl
template <typename Tag = impl::Types, typename... Ts>
consteval auto GetTypeListForTag() {
return impl::GetTypeListForTag<Tag>(TypeList<Ts...>{});
};
/*
static_assert(kTypeId<int> == 0);
static_assert(kTypeId<void> == 1);
static_assert(std::is_same_v<decltype(GetTypeListForTag()), TypeList<int, void>>);
*/
} // namespace utempl