fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. template<typename T, size_t X, size_t Y>
  5. void sort2(T(&arr)[X][Y])
  6. {
  7. T *p = reinterpret_cast<T *>(&arr);
  8. std::sort(p, p + X*Y);
  9. }
  10.  
  11. int main()
  12. {
  13. int a[3][4] = { { 1,3,2,4 }, { 2,1,5,3 }, { 0,8,2,3 } };
  14. char b[2][5] = { { 'h','e','l','l','o' }, { 'w','o','r','l','d' }};
  15.  
  16. sort2(a);
  17.  
  18. for (size_t i = 0; i < 3; ++i)
  19. {
  20. for (size_t j = 0; j < 4; ++j)
  21. std::cout << a[i][j] << " ";
  22. std::cout << std::endl;
  23. }
  24.  
  25. sort2(b);
  26.  
  27. for (size_t i = 0; i < 2; ++i)
  28. {
  29. for (size_t j = 0; j < 5; ++j)
  30. std::cout << b[i][j] << " ";
  31. std::cout << std::endl;
  32. }
  33. }
Success #stdin #stdout 0s 4196KB
stdin
Standard input is empty
stdout
0 1 1 2 
2 2 3 3 
3 4 5 8 
d e h l l 
l o o r w