From 25af8c9d8fbc3c1707002f82969c032b66156e13 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 26 Sep 2024 16:40:20 +0200 Subject: [PATCH] feat: `for_each` on `std::tuple` added --- src/core/include/mp-units/ext/algorithm.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/include/mp-units/ext/algorithm.h b/src/core/include/mp-units/ext/algorithm.h index 564000ac..15e3ad7b 100644 --- a/src/core/include/mp-units/ext/algorithm.h +++ b/src/core/include/mp-units/ext/algorithm.h @@ -35,6 +35,8 @@ import std; #include #include #include +#include +#include #endif #endif @@ -150,4 +152,16 @@ constexpr ForwardIt2 swap_ranges(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 return first2; } +template +constexpr void for_each_impl(const std::tuple& t, F&& func, std::index_sequence) +{ + (..., func(std::get(t))); +} + +template +constexpr void for_each(const std::tuple& t, F&& func) +{ + for_each_impl(t, std::forward(func), std::index_sequence_for{}); +} + } // namespace mp_units::detail