From: Kefu Chai Date: Tue, 22 Nov 2022 04:03:15 +0000 (+0800) Subject: crimson/osd: add formatter for std::optional<> X-Git-Tag: v18.1.0~846^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8c118d630efa2e129cdfd9835c816eb040af3d2d;p=ceph-ci.git 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 --- 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;