#include <iostream>
#include <functional>
using namespace std;
struct Functor
{
template<typename T>
void operator()(T& t) const { std::cout << t << std::endl; }
};
template<std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
for_index(int, std::tuple<Tp...> &, FuncT)
{ }
template<std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I < sizeof...(Tp), void>::type
for_index(int index, std::tuple<Tp...>& t, FuncT f)
{
if (index == 0) f(std::get<I>(t));
for_index<I + 1, FuncT, Tp...>(index-1, t, f);
}
int main() {
auto t = make_tuple(1, 2, "abc", "def", 4.0f);
int i = 2; // for example
for_index(i, t, Functor());
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBGdW5jdG9yIAp7CiAgICB0ZW1wbGF0ZTx0eXBlbmFtZSBUPgogICAgdm9pZCBvcGVyYXRvcigpKFQmIHQpIGNvbnN0IHsgc3RkOjpjb3V0IDw8IHQgPDwgc3RkOjplbmRsOyB9Cn07Cgp0ZW1wbGF0ZTxzdGQ6OnNpemVfdCBJID0gMCwgdHlwZW5hbWUgRnVuY1QsIHR5cGVuYW1lLi4uIFRwPgppbmxpbmUgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8SSA9PSBzaXplb2YuLi4oVHApLCB2b2lkPjo6dHlwZQogIGZvcl9pbmRleChpbnQsIHN0ZDo6dHVwbGU8VHAuLi4+ICYsIEZ1bmNUKQogIHsgfQoKdGVtcGxhdGU8c3RkOjpzaXplX3QgSSA9IDAsIHR5cGVuYW1lIEZ1bmNULCB0eXBlbmFtZS4uLiBUcD4KaW5saW5lIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPEkgPCBzaXplb2YuLi4oVHApLCB2b2lkPjo6dHlwZQogIGZvcl9pbmRleChpbnQgaW5kZXgsIHN0ZDo6dHVwbGU8VHAuLi4+JiB0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