Support pretty-printing matrices
This commit is contained in:
parent
5e61832a9b
commit
5eef1e13f5
1 changed files with 20 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#include <psemek/geom/math.hpp>
|
#include <psemek/geom/math.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace psemek::geom
|
namespace psemek::geom
|
||||||
|
|
@ -375,4 +376,23 @@ namespace psemek::geom
|
||||||
return os;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue