From: Patrick Donnelly Date: Thu, 29 May 2025 12:58:08 +0000 (-0400) Subject: common: break print template into separate header X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=92f6711332ea3f4a42c58ee46ad6296afea1553c;p=ceph-ci.git common: break print template into separate header To avoid pulling in all the debug includes for some primitive headers. Signed-off-by: Patrick Donnelly (cherry picked from commit d702f8e19f2ce72dc1fc8a7b029f792ec9d23075) --- diff --git a/src/common/CanHasPrint.h b/src/common/CanHasPrint.h new file mode 100644 index 00000000000..9f1140c56f4 --- /dev/null +++ b/src/common/CanHasPrint.h @@ -0,0 +1,29 @@ +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2025 IBM, Inc. + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#pragma once + +#include +#include + +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; +} diff --git a/src/common/dout.h b/src/common/dout.h index 4fed3d9178d..ff33c3844c2 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -18,6 +18,7 @@ #include +#include "common/CanHasPrint.h" #include "include/ceph_assert.h" #include "include/common_fwd.h" #ifdef WITH_CRIMSON @@ -44,18 +45,6 @@ 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;