Range/Loop through N variables in [modern] C++
What's a succinct way of ranging through N variables, of any type each, to perform an operation? Let's say I have variables a , b , c , d , e and want to go through all of them performing some operation. Use Boost.Hana and generic lambdas: #include <tuple> #include <iostream> #include <boost/hana.hpp> #include <boost/hana/ext/std/tuple.hpp> struct A {}; struct B {}; struct C {}; struct D {}; struct E {}; int main() { using namespace std; using boost::hana::for_each; A a; B b; C c; D d; E e; for_each(tie(a, b, c, d, e), [](auto &x) { cout << typeid(x).name() << endl; }); } http://coliru.stacked