fork(1) download
  1. #include <iostream>
  2. #include <list>
  3. #include <utility>
  4. #include <vector>
  5.  
  6. template <typename Func, typename T, std::size_t ... Is>
  7. decltype(auto) apply(Func&& f, const std::list<T>& pars, std::index_sequence<Is...>)
  8. {
  9. std::vector<T> v(pars.rbegin(), pars.rend());
  10.  
  11. return std::forward<Func>(f)(v.at(Is)...);
  12. }
  13.  
  14. template <std::size_t N, typename Func, typename T>
  15. decltype(auto) apply(Func&& f, const std::list<T>& pars)
  16. {
  17. return apply(std::forward<Func>(f), pars, std::make_index_sequence<N>());
  18. }
  19.  
  20. void print(int a, int b, int c, int d, int e, int f)
  21. {
  22. std::cout << a << " " << b << " "<< c << " "<< d << " "<< e << " "<< f << std::endl;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28. const std::list<int> l{4, 8, 15, 16, 23, 42};
  29.  
  30. apply<6>(print, l);
  31. }
  32.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
42 23 16 15 8 4