From: Radoslaw Zarzynski Date: Wed, 19 May 2021 12:28:31 +0000 (+0000) Subject: common: introduce std::optional-returning variants of cmd_getval(). X-Git-Tag: v17.1.0~1853^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5cb65dc74dc3e3e6f75745666a687371ce1230ef;p=ceph.git 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 --- 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