Add std::format support for matrices
This commit is contained in:
parent
892662307f
commit
3a22c74ce5
1 changed files with 27 additions and 0 deletions
|
|
@ -547,3 +547,30 @@ namespace psemek::math
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <typename T, std::size_t R, std::size_t C, typename Char>
|
||||
struct formatter<::psemek::math::matrix<T, R, C>, Char>
|
||||
: formatter<T>
|
||||
{
|
||||
using formatter<T>::parse;
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(::psemek::math::matrix<T, R, C> const & m, FormatContext & ctx) const
|
||||
{
|
||||
for (std::size_t i = 0; i < m.rows(); ++i)
|
||||
{
|
||||
for (std::size_t j = 0; j < m.columns(); ++j)
|
||||
{
|
||||
ctx.advance_to(formatter<T>::format(m[i][j], ctx));
|
||||
ctx.advance_to(std::format_to(ctx.out(), " "));
|
||||
}
|
||||
ctx.advance_to(std::format_to(ctx.out(), "\n"));
|
||||
}
|
||||
return ctx.out();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue