diff --git a/include/omath/angle.hpp b/include/omath/angle.hpp index ee53921..0126158 100644 --- a/include/omath/angle.hpp +++ b/include/omath/angle.hpp @@ -5,8 +5,8 @@ #pragma once #include "omath/angles.hpp" #include -#include #include +#include namespace omath { @@ -150,17 +150,28 @@ namespace omath } }; } // namespace omath -template -struct std::formatter> // NOLINT(*-dcl58-cpp) +// partial specialization of std::formatter for omath::Angle +template +struct std::formatter, CharT> { + using AngleT = omath::Angle; + + // required: default ctor is implicitly OK + + // parse with the correct CharT-aware context [[nodiscard]] - static constexpr auto parse(std::format_parse_context& ctx) + static constexpr auto parse(std::basic_format_parse_context& ctx) + -> std::basic_format_parse_context::iterator { - return ctx.begin(); + return ctx.begin(); // no custom format specifiers } - [[nodiscard]] - static auto format(const omath::Angle& deg, std::format_context& ctx) + + // format; here we only implement for narrow char to keep it simple + template + auto format(const AngleT& deg, FormatContext& ctx) const { - return std::format_to(ctx.out(), "{}deg", deg.as_degrees()); + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), "{}deg", deg.as_degrees()); + return std::format_to(ctx.out(), L"{}deg", deg.as_degrees()); } }; \ No newline at end of file