From 86b24ea9269caa2dfc10f11ad58cb4a1d2ba9658 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Wed, 26 Jun 2024 02:43:28 +0000 Subject: [PATCH] Add kSeq. Use kSeq instead make_index_sequence in functions --- include/utempl/utils.hpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index 7b863bd..1dc6c1e 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -23,6 +23,24 @@ struct Wrapper { template inline constexpr Wrapper kWrapper; +namespace impl { + +template +struct kSeq {}; + +} // namespace impl + +template +inline constexpr impl::kSeq kSeq; + +template +constexpr auto operator|(F&& f, impl::kSeq) { + return [&](std::index_sequence){ + return std::forward(f)(kWrapper...); + }(std::make_index_sequence()); +}; + + template consteval auto ParseNumber() -> T { @@ -300,9 +318,9 @@ inline constexpr auto operator|(Tuple&& tuple, FF&& f) { template inline constexpr auto Unpack(Tuple&& tuple, F&& f) -> decltype(auto) { - return [&](std::index_sequence) -> decltype(auto) { - return f(Get(std::forward(tuple))...); - }(std::make_index_sequence>()); + return [&](auto... is) -> decltype(auto) { + return f(Get(std::forward(tuple))...); + } | kSeq>; }; template @@ -450,10 +468,9 @@ inline constexpr auto Tie(Ts&... args) -> Tuple { }; template