feat: for_each on std::tuple added

This commit is contained in:
Mateusz Pusz
2024-09-26 16:40:20 +02:00
parent 922907890f
commit 25af8c9d8f

View File

@@ -35,6 +35,8 @@ import std;
#include <compare>
#include <initializer_list>
#include <iterator>
#include <tuple>
#include <utility>
#endif
#endif
@@ -150,4 +152,16 @@ constexpr ForwardIt2 swap_ranges(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2
return first2;
}
template<typename... Ts, typename F, std::size_t... Is>
constexpr void for_each_impl(const std::tuple<Ts...>& t, F&& func, std::index_sequence<Is...>)
{
(..., func(std::get<Is>(t)));
}
template<typename... Ts, typename F>
constexpr void for_each(const std::tuple<Ts...>& t, F&& func)
{
for_each_impl(t, std::forward<F>(func), std::index_sequence_for<Ts...>{});
}
} // namespace mp_units::detail