From 62c1304ddb466c627e4292b615ce1ca69a8797d8 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Tue, 19 Mar 2024 15:14:27 +0000 Subject: [PATCH] Add find to TupleLike --- include/utempl/utils.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index 7e6b2cb..a85134d 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -291,6 +291,19 @@ inline constexpr auto Curry(F&& f) -> Curryer> { return {.f = std::forward(f), .data = Tuple{}}; }; - +template +inline constexpr auto Find(Tuple&& tuple, T&& find) -> std::size_t { + return [&](std::index_sequence) -> std::size_t { + std::array> bs{Overloaded( + [&](const T& element){ + return element == find; + }, + [](auto&&) { + return false; + } + )(Get(tuple))...}; + return std::ranges::find(bs, true) - bs.begin(); + }(std::make_index_sequence>()); +}; } // namespace utempl