From c91f3a9c093c0dd6a9f589cacf8c62d94d6a7e7a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 15 Mar 2024 10:10:01 +0800 Subject: [PATCH] util: add fmt::formatter for bool_class this change addresses the formatting with fmtlib v10, which stopped creating the default-generated formatter even if FMT_DEPRECATED_OSTREAM preprocess macro is defined. so to enable Seastar applications to print bool_class using {fmt} without defining the formatter by themselves, we provide the formatter for this class in Seastar. the operator<< for bool_class is preserved for backward compatibility. please note, {fmt} format a `bool` variable as "true" or "false" based on its value, so we don't have to put "true" or "false" explicitly as we do in the implementation of operator<<. Refs https://github.com/scylladb/scylladb/issues/13245 Signed-off-by: Kefu Chai Closes #2144 --- include/seastar/util/bool_class.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/seastar/util/bool_class.hh b/include/seastar/util/bool_class.hh index fd28078af91..3ba028e0ae3 100644 --- a/include/seastar/util/bool_class.hh +++ b/include/seastar/util/bool_class.hh @@ -22,6 +22,7 @@ #pragma once #include +#include namespace seastar { @@ -101,3 +102,12 @@ const bool_class bool_class::no { false }; /// @} } + +template +struct fmt::formatter> { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + template + auto format(seastar::bool_class v, FormatContext& ctx) const{ + return fmt::format_to(ctx.out(), "{}", bool(v)); + } +};