Support pretty-printing matrices

This commit is contained in:
Nikita Lisitsa 2023-12-28 17:15:15 +03:00
parent 5e61832a9b
commit 5eef1e13f5

View file

@ -5,6 +5,7 @@
#include <psemek/geom/math.hpp>
#include <iostream>
#include <iomanip>
#include <algorithm>
namespace psemek::geom
@ -375,4 +376,23 @@ namespace psemek::geom
return os;
}
template <typename T, std::size_t R, std::size_t C>
struct setw
{
matrix<T, R, C> const & m;
int w;
};
template <typename T, std::size_t R, std::size_t C>
std::ostream & operator << (std::ostream & os, setw<T, R, C> const & w)
{
for (std::size_t i = 0; i < R; ++i)
{
for (std::size_t j = 0; j < C; ++j)
os << std::fixed << std::right << std::setw(w.w) << w.m[i][j] << ' ';
os << '\n';
}
return os;
}
}