]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson: trade operator<<() for fmt::format<>()
authorKefu Chai <tchaikov@gmail.com>
Thu, 15 Dec 2022 09:36:05 +0000 (17:36 +0800)
committerKefu Chai <tchaikov@gmail.com>
Fri, 16 Dec 2022 02:37:25 +0000 (10:37 +0800)
so we are able to format Payload using fmtlib v9. before fmtlib v9,
fmtlib is able to fall back to the operator<<() to format the the
types with the operator<<() defined. but after fmtlib v9, we need to
explicitly define them for accessing the specialized formatter.

now that we have specialized fmt::format<> for Payload, and the only
consumer of operator<<() is the fmtlib, we can safely drop the latter.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/test/crimson/test_messenger_thrash.cc

index 3d1f6044c3afd328ae9b7bd5e789c8e4f8623b53..2806cc630e2b8f67068c53a35ab4052554e2279e 100644 (file)
@@ -49,11 +49,13 @@ struct Payload {
 };
 WRITE_CLASS_DENC(Payload)
 
-std::ostream& operator<<(std::ostream& out, const Payload &pl)
-{
-  return out << "reply=" << pl.who << " i = " << pl.seq;
-}
-
+template<>
+struct fmt::formatter<Payload> : fmt::formatter<std::string_view> {
+  template <typename FormatContext>
+  auto format(const Payload& pl, FormatContext& ctx) const {
+    return fmt::format_to(ctx.out(), "reply={} i={}", pl.who, pl.seq);
+  }
+};
 
 namespace {