fork(8) download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. void fun (const std::initializer_list<std::string>& strings) {
  5. for(auto s : strings)
  6. {
  7. std::cout << s << " ";
  8. }
  9. }
  10.  
  11. template<typename ...Args>
  12. void foo () {
  13. fun({Args::value...});
  14. }
  15.  
  16. struct A { static std::string value; };
  17. struct B { static std::string value; };
  18. struct C { static std::string value; };
  19. struct D { static std::string value; };
  20.  
  21. std::string A::value = "Hello";
  22. std::string B::value = "World";
  23. std::string C::value = "of";
  24. std::string D::value = "Variadic Templates";
  25.  
  26. int main()
  27. {
  28. foo<A, B, C, D>(); // where A, B, C, D are classes
  29. }
  30.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
Hello World of Variadic Templates