fork download
  1. #include <iostream>
  2.  
  3. template <size_t... Is>
  4. struct index_sequence{};
  5.  
  6. namespace detail {
  7. template <size_t I,size_t...Is>
  8. struct make_index_sequence_impl : make_index_sequence_impl<I-1,I,Is...> {};
  9.  
  10. template <size_t...Is>
  11. struct make_index_sequence_impl<0,Is...>
  12. {
  13. using type = index_sequence<0,Is...>;
  14. };
  15. }
  16.  
  17. template<size_t N>
  18. using make_index_sequence = typename detail::make_index_sequence_impl<N>::type;
  19.  
  20.  
  21. template<size_t I>
  22. void templated_func()
  23. {
  24. std::cout << "templated_func" << I << std::endl;
  25. }
  26.  
  27. template <size_t... Is>
  28. void call_templated_func(index_sequence< Is...>)
  29. {
  30. using do_ = int[];
  31. do_ {0,(templated_func<Is>(),0)...,0};
  32. }
  33.  
  34. int main()
  35. {
  36. call_templated_func(make_index_sequence< 10>());
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
templated_func0
templated_func1
templated_func2
templated_func3
templated_func4
templated_func5
templated_func6
templated_func7
templated_func8
templated_func9
templated_func10