fork download
  1. #include<iostream>
  2.  
  3. template < class Type, int N >struct Point
  4. {
  5. template<class ... Args> Point( Args&&... args )
  6. {
  7. const Type arr[]={ args... };
  8.  
  9. enum { SIZE = sizeof(arr)/sizeof(Type) };
  10.  
  11. static_assert(SIZE<= N, "INVALID_SIZE");
  12.  
  13. for(size_t n=0;n<SIZE;++n) m_values[n]=arr[n];
  14. for(size_t n=SIZE;n<N;++n) m_values[n]=0;
  15. }
  16.  
  17. void View()const
  18. {
  19. std::cout<<"---BEGIN--------------------------\n";
  20. for(size_t n=0;n<N;++n) std::cout<<n<<") "<<m_values[n]<<'\n';
  21. std::cout<<"---END----------------------------\n";
  22. }
  23. Type m_values[N];
  24. };
  25.  
  26.  
  27. int main()
  28. {
  29. int v=10;
  30. Point<int,10> p(1,2,3,4,v);
  31. p.View();
  32. return 0;
  33. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
---BEGIN--------------------------
0) 1
1) 2
2) 3
3) 4
4) 10
5) 0
6) 0
7) 0
8) 0
9) 0
---END----------------------------