#pragma once #include #if __cplusplus >= 202002L #include #define TUPLE_T stdx::tuple #define TUPLE_GET stdx::get #else #include #define TUPLE_T std::tuple #define TUPLE_GET std::get #endif #include #include #include namespace stdx { inline namespace v1 { namespace detail { template struct for_each_n_args; template struct for_each_n_args, std::index_sequence> { template static auto apply(F &&f, T &&t) -> void { (exec(f, std::forward(t)), ...); } private: template static auto exec(F &&f, T &&t) -> void { std::invoke(f, TUPLE_GET(std::forward(t))...); } }; } // namespace detail template void for_each_n_args(F &&f, Args &&...args) { constexpr auto batch_size = [] { if constexpr (N == 0) { return arity_t::value; } else { return N; } }(); static_assert(sizeof...(Args) % batch_size == 0, "for_each_n_args: number of args must be a multiple of the " "given N (or function arity)"); using tuple_t = TUPLE_T; detail::for_each_n_args< std::make_index_sequence, std::make_index_sequence>::apply(std::forward(f), tuple_t{std::forward( args)...}); } } // namespace v1 } // namespace stdx #undef TUPLE_T #undef TUPLE_GET