]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/fmt_common.h: move optional<T> formatter from pg.cc
authorSamuel Just <sjust@redhat.com>
Tue, 19 Sep 2023 22:06:59 +0000 (15:06 -0700)
committerSamuel Just <sjust@redhat.com>
Mon, 11 Dec 2023 04:10:17 +0000 (04:10 +0000)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/common/fmt_common.h
src/crimson/osd/pg.cc

index d68d6457dcb886367fe72aa2e3b6bb94f521f751..27e488aedcebfd2ea1b1da6cc1f3cff10bae6799 100644 (file)
@@ -2,6 +2,8 @@
 // vim: ts=8 sw=2 smarttab
 #pragma once
 
+#include <optional>
+
 /**
  * \file default fmtlib formatters for specifically-tagged types
  */
@@ -61,4 +63,17 @@ struct formatter<T> {
   }
   bool verbose{true};
 };
+
+template <typename T>
+struct formatter<std::optional<T>> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+  template <typename FormatContext>
+  auto format(const std::optional<T> &v, FormatContext& ctx) const {
+    if (v.has_value()) {
+      return fmt::format_to(ctx.out(), "{}", *v);
+    }
+    return fmt::format_to(ctx.out(), "<null>");
+  }
+};
+
 }  // namespace fmt
index e303ecf9a45c8e5de9f9ebbcd54ee7ae114eb936..013f564b5f12aaabe440abc863585bfea4ecd468 100644 (file)
@@ -64,17 +64,6 @@ std::ostream& operator<<(std::ostream& out, const signedspan& d)
 }
 }
 
-template <typename T>
-struct fmt::formatter<std::optional<T>> : fmt::formatter<T> {
-  template <typename FormatContext>
-  auto format(const std::optional<T>& v, FormatContext& ctx) const {
-    if (v.has_value()) {
-      return fmt::formatter<T>::format(*v, ctx);
-    }
-    return fmt::format_to(ctx.out(), "<null>");
-  }
-};
-
 namespace crimson::osd {
 
 using crimson::common::local_conf;