#ifndef ARGPARSER_TUPLE_ITERATION_H #define ARGPARSER_TUPLE_ITERATION_H #include // adapted from https://blog.tartanllama.xyz/exploding-tuples-fold-expressions/ namespace argparser::internal::tuple_foreach_impl { template auto make_index_dispatcher(std::index_sequence) { return [](auto &&f) { (f(std::integral_constant{}), ...); }; } template auto make_index_dispatcher() { return make_index_dispatcher(std::make_index_sequence{}); } }// namespace argparser::internal::tuple_foreach_impl namespace argparser::internal { template void tuple_foreach(Tuple &&t, Func &&f) { constexpr auto n = std::tuple_size>::value; auto dispatcher = internal::tuple_foreach_impl::make_index_dispatcher(); dispatcher([&f, &t](auto idx) { f(std::get(std::forward(t)), idx); }); } }// namespace argparser::internal #endif//ARGPARSER_TUPLE_ITERATION_H