Add + operator and Filter to TypeList

This commit is contained in:
sha512sum 2024-02-28 20:23:41 +00:00
parent 5b1bd8e9a6
commit f8a4d388c5

View file

@ -4,6 +4,7 @@
#include <array> #include <array>
#include <ranges> #include <ranges>
namespace utempl { namespace utempl {
namespace impl { namespace impl {
@ -29,6 +30,12 @@ template <typename... Ts, typename... TTs>
consteval auto operator==(const TypeList<Ts...>& first, const TypeList<TTs...>& second) -> bool { consteval auto operator==(const TypeList<Ts...>& first, const TypeList<TTs...>& second) -> bool {
return std::same_as<decltype(first), decltype(second)>; return std::same_as<decltype(first), decltype(second)>;
}; };
template <typename... Ts, typename... TTs>
consteval auto operator+(const TypeList<Ts...>&, const TypeList<TTs...>&) -> TypeList<Ts..., TTs...> {
return {};
};
template <std::size_t... Is, typename T> template <std::size_t... Is, typename T>
consteval auto Get(std::index_sequence<Is...>, decltype(impl::Caster(Is))..., T, ...) -> T; consteval auto Get(std::index_sequence<Is...>, decltype(impl::Caster(Is))..., T, ...) -> T;
@ -52,5 +59,10 @@ template <typename... Ts>
consteval auto Transform(TypeList<Ts...>, auto&& f) -> TypeList<decltype(f(TypeList<Ts>{}))...> { consteval auto Transform(TypeList<Ts...>, auto&& f) -> TypeList<decltype(f(TypeList<Ts>{}))...> {
return {}; return {};
}; };
template <typename... Ts>
consteval auto Filter(TypeList<Ts...>, auto&& f) {
return ([](auto&& list){if constexpr(decltype(f(list))::kValue) {return list;} else {return kTypeList<>;}}(kType<Ts>) + ...);
};
} // namespace utempl } // namespace utempl