From 92df0fcc649345f438d0d7cc6fab658c02060f07 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 16 Jan 2024 13:59:47 -0500 Subject: [PATCH] common: provide a template for object dumps Signed-off-by: Patrick Donnelly --- src/common/dout.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/common/dout.h b/src/common/dout.h index 6516060c5438e..8d05b12fbe2b3 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -44,6 +44,18 @@ inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) { return out; } +template +concept HasPrint = requires(T t, std::ostream& u) { + { t.print(u) } -> std::same_as; +}; + +template requires HasPrint +static inline std::ostream& operator<<(std::ostream& out, T&& t) +{ + t.print(out); + return out; +} + class DoutPrefixProvider { public: virtual std::ostream& gen_prefix(std::ostream& out) const = 0; -- 2.39.5