From 5cb65dc74dc3e3e6f75745666a687371ce1230ef Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 19 May 2021 12:28:31 +0000 Subject: [PATCH] common: introduce std::optional-returning variants of cmd_getval(). Using an output paramter instead of returning is confusing but common in pre-C++11 code. Let's modernize `cmd_getval()`. Signed-off-by: Radoslaw Zarzynski --- src/common/cmdparse.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/common/cmdparse.h b/src/common/cmdparse.h index da3baaff79d91..0dec47773a398 100644 --- a/src/common/cmdparse.h +++ b/src/common/cmdparse.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include "include/ceph_assert.h" // boost clobbers this @@ -77,6 +78,18 @@ bool cmd_getval(const cmdmap_t& cmdmap, } } +template +std::optional cmd_getval(const cmdmap_t& cmdmap, + std::string_view k) +{ + T ret; + if (const bool found = cmd_getval(cmdmap, k, ret); found) { + return std::make_optional(std::move(ret)); + } else { + return std::nullopt; + } +} + // with default template -- 2.39.5