From 86be835fef0a4c46f379c26d4cf4d6cedff16bda Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 15 Dec 2022 17:36:05 +0800 Subject: [PATCH] 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 --- src/test/crimson/test_messenger_thrash.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 { -- 2.39.5