From e802a1309cf8ad21ffb72d2fb9ea31f8914f77e8 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Tue, 3 Jan 2023 11:42:36 +0200 Subject: [PATCH] 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 --- src/common/Formatter.h | 7 +++++++ 1 file changed, 7 insertions(+) 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(); -- 2.39.5