Add Enumerate, TakeFrom, PushTo, Erase functions
This commit is contained in:
parent
25cc675942
commit
0336a5ab33
2 changed files with 28 additions and 0 deletions
|
@ -97,4 +97,23 @@ consteval auto Size(TypeList<Ts...>) -> std::size_t {
|
||||||
return sizeof...(Ts);
|
return sizeof...(Ts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <std::size_t N, std::size_t From = 0, typename... Ts>
|
||||||
|
consteval auto TakeFrom(TypeList<Ts...> list)
|
||||||
|
requires(N + From <= sizeof...(Ts))
|
||||||
|
{
|
||||||
|
return [&]<std::size_t... Is>(std::index_sequence<Is...>) -> TypeList<decltype(Get<Is + From>(list))...> {
|
||||||
|
return {};
|
||||||
|
}(std::make_index_sequence<N>());
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, std::size_t N, typename... Ts>
|
||||||
|
consteval auto PushTo(TypeList<Ts...> list) {
|
||||||
|
return TakeFrom<N>(list) + kType<T> + TakeFrom<sizeof...(Ts) - N, N>(list);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <std::size_t N, typename... Ts>
|
||||||
|
consteval auto Erase(TypeList<Ts...> list) {
|
||||||
|
return TakeFrom<N>(list) + TakeFrom<sizeof...(Ts) - N - 1, N + 1>(list);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace utempl
|
} // namespace utempl
|
||||||
|
|
|
@ -597,4 +597,13 @@ inline constexpr auto Generate(T&& value) {
|
||||||
} | kSeq<N>;
|
} | kSeq<N>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <TupleLike Tuple>
|
||||||
|
constexpr auto Enumerate(Tuple&& tuple) {
|
||||||
|
return Unpack(std::forward<Tuple>(tuple), [](auto&&... vs) {
|
||||||
|
return [&](auto... is) {
|
||||||
|
return MakeTuple<Tuple>(std::pair{*is, std::forward<decltype(vs)>(vs)}...);
|
||||||
|
} | kSeq<sizeof...(vs)>;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace utempl
|
} // namespace utempl
|
||||||
|
|
Loading…
Reference in a new issue