fork(3) download
  1. template<unsigned... Is> struct seq{ using type = seq; };
  2.  
  3. template<unsigned I, unsigned... Is>
  4. struct rgen_seq : rgen_seq<I-1, Is..., I-1>{};
  5.  
  6. template<unsigned... Is>
  7. struct rgen_seq<0, Is...> : seq<Is...>{};
  8.  
  9. #include <utility>
  10. #include <iostream>
  11.  
  12. template<typename T>
  13. void ascending_print(T&& t)
  14. {
  15. std::cout << std::forward<T>(t) << " ";
  16. }
  17.  
  18. template<typename T, typename... Args>
  19. void ascending_print(T&& t, Args&&... args)
  20. {
  21. ascending_print(std::forward<T>(t));
  22. ascending_print(std::forward<Args>(args)...);
  23. }
  24.  
  25. #include <tuple>
  26.  
  27. namespace aux{
  28. template<class Tup, unsigned... Is>
  29. void descending_print(Tup&& t, seq<Is...>)
  30. {
  31. ascending_print(std::get<Is>(std::forward<Tup>(t))...);
  32. }
  33. } // aux::
  34.  
  35. template<class... Args>
  36. void descending_print(Args&&... args)
  37. {
  38. auto t = std::forward_as_tuple(std::forward<Args>(args)...);
  39. aux::descending_print(t, rgen_seq<sizeof...(Args)>{});
  40. }
  41.  
  42. int main()
  43. {
  44. ascending_print(42, 3.14, "Hello, World!");
  45. std::cout << std::endl;
  46. descending_print(42, 3.14, "Hello, World!");
  47. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
42 3.14 Hello, World! 
Hello, World! 3.14 42