diff --git a/libs/math/include/psemek/math/box.hpp b/libs/math/include/psemek/math/box.hpp index 09aa56f9..407be6d1 100644 --- a/libs/math/include/psemek/math/box.hpp +++ b/libs/math/include/psemek/math/box.hpp @@ -355,27 +355,19 @@ namespace std template struct formatter<::psemek::math::box, Char> + : formatter<::psemek::math::interval> { - constexpr auto parse(std::format_parse_context & ctx) - { - return ctx.begin(); - } + using formatter<::psemek::math::interval>::parse; - auto format(::psemek::math::point const & p, std::format_context & ctx) const + template + auto format(::psemek::math::box const & b, FormatContext & ctx) const { - if constexpr (N == 0) + for (std::size_t i = 0; i < b.dimension(); ++i) { - return std::format_to(ctx.out(), "()"); - } - else - { - auto out = ctx.out(); - out = std::format_to(out, "({}", p[0]); - for (std::size_t i = 1; i < p.dimension(); ++i) - out = std::format_to(out, ", {}", p[i]); - out = std::format_to(out, ")"); - return out; + if (i > 0) ctx.advance_to(std::format_to(ctx.out(), "x")); + formatter<::psemek::math::interval>::format(b[i], ctx); } + return ctx.out(); } }; diff --git a/libs/math/include/psemek/math/interval.hpp b/libs/math/include/psemek/math/interval.hpp index adb8934d..352c3163 100644 --- a/libs/math/include/psemek/math/interval.hpp +++ b/libs/math/include/psemek/math/interval.hpp @@ -341,15 +341,18 @@ namespace std template struct formatter<::psemek::math::interval, Char> + : formatter { - constexpr auto parse(std::format_parse_context & ctx) - { - return ctx.begin(); - } + using formatter::parse; - auto format(::psemek::math::interval const & i, std::format_context & ctx) const + template + auto format(::psemek::math::interval const & i, FormatContext & ctx) const { - return std::format_to(ctx.out(), "[{} .. {}]", i.min, i.max); + ctx.advance_to(std::format_to(ctx.out(), "[")); + ctx.advance_to(formatter::format(i.min, ctx)); + ctx.advance_to(std::format_to(ctx.out(), " .. ")); + ctx.advance_to(formatter::format(i.max, ctx)); + return std::format_to(ctx.out(), "]"); } }; diff --git a/libs/math/include/psemek/math/point.hpp b/libs/math/include/psemek/math/point.hpp index 8b05a67d..afb4b004 100644 --- a/libs/math/include/psemek/math/point.hpp +++ b/libs/math/include/psemek/math/point.hpp @@ -223,25 +223,24 @@ namespace std template struct hash<::psemek::math::point> { - std::uint64_t operator()(::psemek::math::point const & v) const noexcept + std::uint64_t operator()(::psemek::math::point const & p) const noexcept { hash h; std::uint64_t r = 0; for (std::size_t i = 0; i < N; ++i) - ::psemek::util::hash_combine(r, h(v[i])); + ::psemek::util::hash_combine(r, h(p[i])); return r; } }; template struct formatter<::psemek::math::point, Char> + : formatter { - constexpr auto parse(std::format_parse_context & ctx) - { - return ctx.begin(); - } + using formatter::parse; - auto format(::psemek::math::point const & p, std::format_context & ctx) const + template + auto format(::psemek::math::point const & p, FormatContext & ctx) const { if constexpr (N == 0) { @@ -249,12 +248,13 @@ namespace std } else { - auto out = ctx.out(); - out = std::format_to(out, "({}", p[0]); - for (std::size_t i = 1; i < p.dimension(); ++i) - out = std::format_to(out, ", {}", p[i]); - out = std::format_to(out, ")"); - return out; + ctx.advance_to(std::format_to(ctx.out(), "(")); + for (std::size_t i = 0; i < p.dimension(); ++i) + { + if (i > 0) ctx.advance_to(std::format_to(ctx.out(), ", ")); + formatter::format(p[i], ctx); + } + return std::format_to(ctx.out(), ")"); } } }; diff --git a/libs/math/include/psemek/math/quaternion.hpp b/libs/math/include/psemek/math/quaternion.hpp index 3b644990..df6f6dbb 100644 --- a/libs/math/include/psemek/math/quaternion.hpp +++ b/libs/math/include/psemek/math/quaternion.hpp @@ -346,15 +346,15 @@ namespace std template struct formatter<::psemek::math::quaternion, Char> + : formatter<::psemek::math::vector> { - constexpr auto parse(std::format_parse_context & ctx) - { - return ctx.begin(); - } + using formatter<::psemek::math::vector>::parse; - auto format(::psemek::math::quaternion const & q, std::format_context & ctx) const + template + auto format(::psemek::math::quaternion const & q, FormatContext & ctx) const { - return std::format_to(ctx.out(), "{}", q.coords); + formatter<::psemek::math::vector>::format(q.coords, ctx); + return ctx.out(); } }; diff --git a/libs/math/include/psemek/math/vector.hpp b/libs/math/include/psemek/math/vector.hpp index 5c9d9709..e53a5ffb 100644 --- a/libs/math/include/psemek/math/vector.hpp +++ b/libs/math/include/psemek/math/vector.hpp @@ -524,13 +524,12 @@ namespace std template struct formatter<::psemek::math::vector, Char> + : formatter { - constexpr auto parse(std::format_parse_context & ctx) - { - return ctx.begin(); - } + using formatter::parse; - auto format(::psemek::math::vector const & v, std::format_context & ctx) const + template + auto format(::psemek::math::vector const & v, FormatContext & ctx) const { if constexpr (N == 0) { @@ -538,12 +537,13 @@ namespace std } else { - auto out = ctx.out(); - out = std::format_to(out, "({}", v[0]); - for (std::size_t i = 1; i < v.dimension(); ++i) - out = std::format_to(out, ", {}", v[i]); - out = std::format_to(out, ")"); - return out; + ctx.advance_to(std::format_to(ctx.out(), "(")); + for (std::size_t i = 0; i < v.dimension(); ++i) + { + if (i > 0) ctx.advance_to(std::format_to(ctx.out(), ", ")); + formatter::format(v[i], ctx); + } + return std::format_to(ctx.out(), ")"); } } };