Add find to TupleLike

This commit is contained in:
sha512sum 2024-03-19 15:14:27 +00:00
parent 6a21ea68bb
commit 62c1304ddb

View file

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