From: Kefu Chai Date: Thu, 15 Dec 2022 09:36:05 +0000 (+0800) Subject: test/crimson: trade operator<<() for fmt::format<>() X-Git-Tag: v18.1.0~633^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=86be835fef0a4c46f379c26d4cf4d6cedff16bda;p=ceph.git test/crimson: trade operator<<() for fmt::format<>() 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 --- diff --git a/src/test/crimson/test_messenger_thrash.cc b/src/test/crimson/test_messenger_thrash.cc index 3d1f6044c3afd..2806cc630e2b8 100644 --- a/src/test/crimson/test_messenger_thrash.cc +++ b/src/test/crimson/test_messenger_thrash.cc @@ -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 : fmt::formatter { + template + auto format(const Payload& pl, FormatContext& ctx) const { + return fmt::format_to(ctx.out(), "reply={} i={}", pl.who, pl.seq); + } +}; namespace {