fork download
  1. #include <array>
  2. #include <cstddef>
  3. #include <iostream>
  4.  
  5. template<std::size_t n>
  6. class float_vec
  7. {
  8. private:
  9. std::array<float, n> underlying_array;
  10.  
  11. public:
  12. template<typename... Types>
  13. float_vec(Types... args) : underlying_array{{args...}}
  14. {
  15. }
  16.  
  17. float get(int index) {return underlying_array[index];}
  18. };
  19.  
  20. int main()
  21. {
  22. float_vec<4> v = {1.0f, 2.0f, 3.0f, 4.5f};
  23.  
  24. for (int i = 0; i < 4; ++i)
  25. {
  26. std::cout<<v.get(i)<<" ";
  27. }
  28. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1 2 3 4.5