From: Ronen Friedman Date: Tue, 3 Jan 2023 09:42:36 +0000 (+0200) Subject: common: add a factory function returning unique_ptr to Formatter API X-Git-Tag: v18.1.0~443^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e802a1309cf8ad21ffb72d2fb9ea31f8914f77e8;p=ceph.git common: add a factory function returning unique_ptr to Formatter API As the testing code (but not just) is full of the following sequence: - dyn-allocating a Formatter; - using it in its 'naked pointer' form; - deleting it; which is not a recommended practice. Signed-off-by: Ronen Friedman --- diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 6751e4709ce0b..abdc172cba53b 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -62,6 +63,12 @@ namespace ceph { static Formatter *create(std::string_view type) { return create(type, "json-pretty", ""); } + template + static std::unique_ptr create_unique(Params &&...params) + { + return std::unique_ptr( + Formatter::create(std::forward(params)...)); + } Formatter(); virtual ~Formatter();