#pragma once #include namespace sp { /// @brief Concat multiple tuples in one big tuple /// @tparam ...input_t Multiple std::tuple types to concat template using tuple_cat_t = decltype(std::tuple_cat(std::declval()...)); namespace details { template class TupleForEachHelper { public: template static void Exec(TTuple&& tuple, TFunc&& func) { using Tuple = typename std::decay::type; static const std::size_t TupleSize = std::tuple_size::value; static_assert(TRem <= TupleSize, "Incorrect parameters"); // Invoke function with current element static const std::size_t Idx = TupleSize - TRem; func(std::get(std::forward(tuple))); // Compile time recursion - invoke function with the remaining elements TupleForEachHelper::Exec(std::forward(tuple), std::forward(func)); } }; template <> class TupleForEachHelper<0> { public: // Stop compile time recursion template static void Exec(TTuple&& tuple, TFunc&& func) { static_cast(tuple); static_cast(func); } }; } // namespace details template void TupleForEach(TFunc&& func, TTuple&& tuple) { using Tuple = typename std::decay::type; static const std::size_t TupleSize = std::tuple_size::value; details::TupleForEachHelper::Exec(std::forward(tuple), std::forward(func)); } } // namespace sp