fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <cstdint>
  4.  
  5. struct Matrix
  6. {
  7. template<typename T, const uint32_t X, const uint32_t Y>
  8. static const std::array<std::array<T, Y>, X> IDENTITY()
  9. {
  10. //const int X = 5, Y = 5;
  11. std::array<std::array<int, Y>, X> mat{};
  12. for (int x = 0; x < X; ++x)
  13. mat[x][x] = 1;
  14.  
  15. return mat;
  16. }
  17. };
  18. int main()
  19. {
  20. std::array<std::array<int, 5>, 5> id = Matrix::IDENTITY<int, 5, 5>();
  21.  
  22.  
  23. for (auto& a : id)
  24. {
  25. for (auto i : a)
  26. {
  27. std::cout << "[" << i << "]";
  28. }
  29. std::cout << std::endl;
  30. }
  31. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
[1][0][0][0][0]
[0][1][0][0][0]
[0][0][1][0][0]
[0][0][0][1][0]
[0][0][0][0][1]