From bfd668cff2ad55e4da259ada2b09b1feabdae8ff Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sat, 31 Jan 2026 13:03:48 +0300 Subject: [PATCH] ... --- mcc_serializer.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mcc_serializer.h b/mcc_serializer.h index 5f2fc8b..a84dff9 100644 --- a/mcc_serializer.h +++ b/mcc_serializer.h @@ -12,10 +12,14 @@ namespace mcc struct mcc_serializer_interface_t { virtual ~mcc_serializer_interface_t() = default; - template SelfT, traits::mcc_output_char_range R, typename ValueT> - mcc_error_c auto operator()(this SelfT&& self, R& output, ValueT&& value) + template SelfT, + traits::mcc_output_char_range R, + typename ValueT, + typename FmtT = std::format_string> + requires(std::same_as> || std::same_as) + mcc_error_c auto operator()(this SelfT&& self, R& output, ValueT&& value, FmtT fmt = "{}") { - return std::forward(self).operator=(output, std::forward(value)); + return std::forward(self).operator=(output, std::forward(value), std::move(fmt)); } }; @@ -23,6 +27,10 @@ template concept mcc_serializer_c = std::derived_from; + +template +class MccSerializer; + template class MccSerializer : public mcc_serializer_interface_t { @@ -35,10 +43,15 @@ public: ~MccSerializer() = default; - error_t operator()(traits::mcc_output_char_range auto& output, VT&& value) + template > + error_t operator()(traits::mcc_output_char_range auto& output, VT&& value, FmtT fmt = "{}") requires std::formattable { - std::format_to(std::back_inserter(output), "{}", value); + if constexpr (std::same_as>) { + std::format_to(std::back_inserter(output), fmt, value); + } else if constexpr (std::same_as) { + std::vformat_to(std::back_inserter(output), fmt, std::make_format_args(value)); + } return {}; } @@ -48,7 +61,6 @@ protected: }; - template class MccSerializer : public mcc_serializer_interface_t {