template
void for_each_in_tuple(const std::tuple & tuple, F func, std::index_sequence){
using expander = int[];
(void)expander { 0, ((void)func(std::get(tuple)), 0)... };
}
template
void for_each_in_tuple(const std::tuple & tuple, F func){
for_each_in_tuple(tuple, func, std::make_index_sequence());
}
Usage:
auto some = std::make_tuple("I am good", 255, 2.1);
for_each_in_tuple(some, [](const auto &x) { std::cout << x << std::endl; });
Demo.
std::index_sequence and family are C++14 features, but they can be easily implemented in C++11 (there are many available on SO). Polymorphic lambdas are also C++14, but can be replaced with a custom-written functor.