From 0336a5ab33388a514676372e3a3da6875a41ae0c Mon Sep 17 00:00:00 2001 From: sha512sum Date: Tue, 9 Jul 2024 00:49:57 +0000 Subject: [PATCH] Add Enumerate, TakeFrom, PushTo, Erase functions --- include/utempl/type_list.hpp | 19 +++++++++++++++++++ include/utempl/utils.hpp | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/include/utempl/type_list.hpp b/include/utempl/type_list.hpp index bb1c075..1268963 100644 --- a/include/utempl/type_list.hpp +++ b/include/utempl/type_list.hpp @@ -97,4 +97,23 @@ consteval auto Size(TypeList) -> std::size_t { return sizeof...(Ts); }; +template +consteval auto TakeFrom(TypeList list) + requires(N + From <= sizeof...(Ts)) +{ + return [&](std::index_sequence) -> TypeList(list))...> { + return {}; + }(std::make_index_sequence()); +}; + +template +consteval auto PushTo(TypeList list) { + return TakeFrom(list) + kType + TakeFrom(list); +}; + +template +consteval auto Erase(TypeList list) { + return TakeFrom(list) + TakeFrom(list); +}; + } // namespace utempl diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index 34d3d86..e3a78f4 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -597,4 +597,13 @@ inline constexpr auto Generate(T&& value) { } | kSeq; }; +template +constexpr auto Enumerate(Tuple&& tuple) { + return Unpack(std::forward(tuple), [](auto&&... vs) { + return [&](auto... is) { + return MakeTuple(std::pair{*is, std::forward(vs)}...); + } | kSeq; + }); +}; + } // namespace utempl