Add std::format support for matrices

This commit is contained in:
Nikita Lisitsa 2026-06-05 23:00:28 +03:00
parent 892662307f
commit 3a22c74ce5

View file

@ -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();
}
};
}