From: Samuel Just Date: Tue, 19 Sep 2023 22:06:59 +0000 (-0700) Subject: common/fmt_common.h: move optional formatter from pg.cc X-Git-Tag: v19.3.0~296^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6e8229b2260c301fe74708f13b61d155de555152;p=ceph.git common/fmt_common.h: move optional formatter from pg.cc Signed-off-by: Samuel Just --- diff --git a/src/common/fmt_common.h b/src/common/fmt_common.h index d68d6457dcb8..27e488aedceb 100644 --- a/src/common/fmt_common.h +++ b/src/common/fmt_common.h @@ -2,6 +2,8 @@ // vim: ts=8 sw=2 smarttab #pragma once +#include + /** * \file default fmtlib formatters for specifically-tagged types */ @@ -61,4 +63,17 @@ struct formatter { } bool verbose{true}; }; + +template +struct formatter> { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + template + auto format(const std::optional &v, FormatContext& ctx) const { + if (v.has_value()) { + return fmt::format_to(ctx.out(), "{}", *v); + } + return fmt::format_to(ctx.out(), ""); + } +}; + } // namespace fmt diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index e303ecf9a45c..013f564b5f12 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -64,17 +64,6 @@ std::ostream& operator<<(std::ostream& out, const signedspan& d) } } -template -struct fmt::formatter> : fmt::formatter { - template - auto format(const std::optional& v, FormatContext& ctx) const { - if (v.has_value()) { - return fmt::formatter::format(*v, ctx); - } - return fmt::format_to(ctx.out(), ""); - } -}; - namespace crimson::osd { using crimson::common::local_conf;