template<unsigned... Is> struct seq{ using type = seq; };
template<unsigned I, unsigned... Is>
struct rgen_seq : rgen_seq<I-1, Is..., I-1>{};
template<unsigned... Is>
struct rgen_seq<0, Is...> : seq<Is...>{};
#include <utility>
#include <iostream>
template<typename T>
void ascending_print(T&& t)
{
std::cout << std::forward<T>(t) << " ";
}
template<typename T, typename... Args>
void ascending_print(T&& t, Args&&... args)
{
ascending_print(std::forward<T>(t));
ascending_print(std::forward<Args>(args)...);
}
#include <tuple>
namespace aux{
template<class Tup, unsigned... Is>
void descending_print(Tup&& t, seq<Is...>)
{
ascending_print(std::get<Is>(std::forward<Tup>(t))...);
}
} // aux::
template<class... Args>
void descending_print(Args&&... args)
{
auto t = std::forward_as_tuple(std::forward<Args>(args)...);
aux::descending_print(t, rgen_seq<sizeof...(Args)>{});
}
int main()
{
ascending_print(42, 3.14, "Hello, World!");
std::cout << std::endl;
descending_print(42, 3.14, "Hello, World!");
}
dGVtcGxhdGU8dW5zaWduZWQuLi4gSXM+IHN0cnVjdCBzZXF7IHVzaW5nIHR5cGUgPSBzZXE7IH07Cgp0ZW1wbGF0ZTx1bnNpZ25lZCBJLCB1bnNpZ25lZC4uLiBJcz4Kc3RydWN0IHJnZW5fc2VxIDogcmdlbl9zZXE8SS0xLCBJcy4uLiwgSS0xPnt9OwoKdGVtcGxhdGU8dW5zaWduZWQuLi4gSXM+CnN0cnVjdCByZ2VuX3NlcTwwLCBJcy4uLj4gOiBzZXE8SXMuLi4+e307CgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8dHlwZW5hbWUgVD4Kdm9pZCBhc2NlbmRpbmdfcHJpbnQoVCYmIHQpCnsKICAgIHN0ZDo6Y291dCA8PCBzdGQ6OmZvcndhcmQ8VD4odCkgPDwgIiAiOwp9Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBULCB0eXBlbmFtZS4uLiBBcmdzPgp2b2lkIGFzY2VuZGluZ19wcmludChUJ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