fork download
  1. #include <iostream>
  2. #include <array>
  3.  
  4. namespace rs {
  5. struct float3 {
  6. float x, y, z;
  7. };
  8. }
  9.  
  10. class foo
  11. {
  12. public:
  13. template <class T>
  14. void bar(T arg1, int arg2, int arg3) {
  15. std::cout << "non-array bar:" << std::endl;
  16. std::cout << " " << arg1 << " " << arg2 << " " << arg3 << std::endl;
  17. }
  18.  
  19. template <size_t size>
  20. void bar(std::array<rs::float3, size> arg1, int arg2) {
  21. std::cout << "array bar:" << std::endl;
  22. for (size_t i = 0; i < size; ++i) {
  23. std::cout << " [" << i << "] = {" << arg1[i].x << "," << arg1[i].y << "," << arg1[i].z << "}" << std::endl;
  24. }
  25. std::cout << " " << arg2 << std::endl;
  26. }
  27. };
  28.  
  29. int main() {
  30. foo f;
  31.  
  32. f.bar("test", 2, 3);
  33.  
  34. std::array<rs::float3, 2> arr;
  35. arr[0].x = arr[0].y = arr[0].z = 1.0;
  36. arr[1].x = arr[1].y = arr[1].z = 2.0;
  37. f.bar(arr, 12345);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 4512KB
stdin
Standard input is empty
stdout
non-array bar:
  test 2 3
array bar:
  [0] = {1,1,1}
  [1] = {2,2,2}
  12345