Fix find for TupleLike

This commit is contained in:
sha512sum 2024-03-23 15:33:50 +00:00
parent 62c1304ddb
commit 149670fb2b

View file

@ -294,16 +294,25 @@ inline constexpr auto Curry(F&& f) -> Curryer<std::remove_cvref_t<F>> {
template <TupleLike Tuple, typename T> template <TupleLike Tuple, typename T>
inline constexpr auto Find(Tuple&& tuple, T&& find) -> std::size_t { inline constexpr auto Find(Tuple&& tuple, T&& find) -> std::size_t {
return [&]<std::size_t... Is>(std::index_sequence<Is...>) -> std::size_t { return [&]<std::size_t... Is>(std::index_sequence<Is...>) -> std::size_t {
using Type = std::remove_cvref_t<T>;
std::array<bool, kTupleSize<Tuple>> bs{Overloaded( std::array<bool, kTupleSize<Tuple>> bs{Overloaded(
[&](const T& element){ [&](const Type& element) {
return element == find;
},
[&](const Type&& element) {
return element == find;
},
[&](Type&& element) {
return element == find;
},
[&](Type& element) {
return element == find; return element == find;
}, },
[](auto&&) { [](auto&&) {
return false; return false;
} }
)(Get<Is>(tuple))...}; )(Get<Is>(std::forward<Tuple>(tuple)))...};
return std::ranges::find(bs, true) - bs.begin(); return std::ranges::find(bs, true) - bs.begin();
}(std::make_index_sequence<kTupleSize<Tuple>>()); }(std::make_index_sequence<kTupleSize<Tuple>>());
}; };
} // namespace utempl } // namespace utempl