From 9cb0811eccf79734338c1d7728820d432072532d Mon Sep 17 00:00:00 2001 From: sha512sum Date: Tue, 26 Mar 2024 08:33:01 +0000 Subject: [PATCH] Add Map, another name for Transform --- include/utempl/utils.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index cdad54b..f6d1261 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -162,13 +162,19 @@ template concept TupleLike = kForceEnableTuple> || (requires{Get<0>(MakeTuple(42));} && impl::IsSafeTuple>::value); -template -inline constexpr auto Transform(Tuple&& container, auto&& f, TypeList = {}) { +template +inline constexpr auto Transform(Tuple&& container, F&& f, TypeList = {}) { return [&](std::index_sequence){ return MakeTuple(f(Get(std::forward(container)))...); }(std::make_index_sequence>()); }; +template +inline constexpr auto Map(Tuple&& tuple, F&& f, TypeList result = {}) { + return Transform(std::forward(tuple), std::forward(f), result); +}; + + template inline constexpr auto Reverse(Tuple&& tuple) { return [&](std::index_sequence) {