From 3a22c74ce57a37bd04463fe6b2dc0af3427bd928 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 5 Jun 2026 23:00:28 +0300 Subject: [PATCH] Add std::format support for matrices --- libs/math/include/psemek/math/matrix.hpp | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libs/math/include/psemek/math/matrix.hpp b/libs/math/include/psemek/math/matrix.hpp index 49bee094..46e6006d 100644 --- a/libs/math/include/psemek/math/matrix.hpp +++ b/libs/math/include/psemek/math/matrix.hpp @@ -547,3 +547,30 @@ namespace psemek::math } } + +namespace std +{ + + template + struct formatter<::psemek::math::matrix, Char> + : formatter + { + using formatter::parse; + + template + auto format(::psemek::math::matrix 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::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(); + } + }; + +}