fork(1) download
  1. #include <iostream>
  2. #include <array>
  3.  
  4. template<class... Args>
  5. void f(Args&... args)
  6. {
  7. for(const auto& a : {args...})
  8. {
  9. std::cout<<a<<std::endl;
  10. }
  11. }
  12.  
  13.  
  14. namespace Helper {
  15. template<unsigned int N,unsigned int I >
  16. struct Caller
  17. {
  18. template<class T, class...Args>
  19. static void call( const std::array<T,N>& arr, Args... args )
  20. {
  21. Caller<N,I-1>::call( arr, std::get<I-1>(arr), args... );
  22. }
  23. };
  24.  
  25. template <unsigned int N>
  26. struct Caller<N, 0>
  27. {
  28. template< class T, class...Args>
  29. static void call(const std::array<T,N>& arr, Args&... args)
  30. {
  31. f(args...);
  32. }
  33. };
  34. }
  35.  
  36. template<typename T, unsigned N>
  37. void call_f(const std::array<T,N>& arr)
  38. {
  39. Helper::Caller<N,N>::call(arr);
  40. }
  41. int main() {
  42.  
  43. std::array<float,3> array = {4.3, 3.14,2.1} ;
  44.  
  45. call_f(array);
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
4.3
3.14
2.1