fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. struct A {};
  5. struct B {};
  6. struct C {};
  7. struct D {};
  8. struct E {};
  9.  
  10. struct F
  11. {
  12. template <typename T>
  13. void operator () (T&& t) {
  14. std::cout << typeid(t).name() << std::endl;
  15. }
  16.  
  17. };
  18.  
  19. template <typename F, typename...Ts>
  20. void apply(F f, Ts&&...args) {
  21. const int dummy[] = { (f(std::forward<Ts>(args)), 0)... };
  22. static_cast<void>(dummy); // avoid warning about unused variable.
  23. }
  24.  
  25. int main() {
  26.  
  27. A a;
  28. B b;
  29. C c;
  30. D d;
  31. E e;
  32.  
  33. apply(F{}, a, b, c, d, e);
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
1A
1B
1C
1D
1E