#include
#include
namespace detail {
template<class Tuple, class F, std::size_t…Is>
void for_each(Tuple&& tuple, F&& f, std::index_sequence<Is…>)
{
using expand = int[];
void(expand{
0,
(f(std::get(std::forward(tuple))), 0)…
});
};
}
template<class Tuple, class F>
void for_each(Tuple&& tuple, F&& f)
{
using base_tuple = std::decay_t;
constexpr auto tuple_size = std::tuple_size<base_tuple>::value;
detail::for_each(std::forward(tuple),
std::forward(f),
std::make_index_sequence<tuple_size>());
}
template<class…Args>
void display(Args&&…args) {
for_each(std::forward_as_tuple(std::forward(args)…), [&](auto&& arg) {
//using arg_type = decltype(arg);
std::cout << arg << std::endl;
});
}
int main()
{
display(1, 2, 3, 4);
}