From 901e718deb4cf0f4a2580aa86b8cb28b4160a083 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 18 Jan 2024 18:07:07 +0100 Subject: [PATCH] feat: text output support added to `basic_fixed_string` --- .../mp-units/bits/external/fixed_string.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/include/mp-units/bits/external/fixed_string.h b/src/core/include/mp-units/bits/external/fixed_string.h index 0e97c20c..d595f907 100644 --- a/src/core/include/mp-units/bits/external/fixed_string.h +++ b/src/core/include/mp-units/bits/external/fixed_string.h @@ -29,6 +29,7 @@ // IWYU pragma: begin_exports #include #include +#include // IWYU pragma: end_exports #include @@ -121,6 +122,13 @@ struct basic_fixed_string { // TODO std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); return detail::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } + + template + friend std::basic_ostream& operator<<(std::basic_ostream& os, + const basic_fixed_string& str) + { + return os << str.c_str(); + } }; template @@ -136,3 +144,12 @@ template using fixed_string = basic_fixed_string; } // namespace mp_units + +template +struct MP_UNITS_STD_FMT::formatter> : formatter> { + template + auto format(const mp_units::basic_fixed_string& str, FormatContext& ctx) + { + return formatter>::format(str.view(), ctx); + } +};