From 8c118d630efa2e129cdfd9835c816eb040af3d2d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 22 Nov 2022 12:03:15 +0800 Subject: [PATCH] crimson/osd: add formatter for std::optional<> in `PG::do_update_log_missing()`, `std::optional` is printed using {fmt}, but {fmt} does not support formatting `std::optional<>`. so we need to swing our own formatter. we can promote this formatter to a more common place if it is proved to be useful otherwhere in the source tree. Signed-off-by: Kefu Chai --- src/crimson/osd/pg.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index a1808427ac3..248b510cfbc 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -58,6 +58,17 @@ 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; -- 2.39.5