From: Adam C. Emerson Date: Thu, 17 Aug 2017 00:42:00 +0000 (-0400) Subject: common: Add maybe_timespan X-Git-Tag: wip-pdonnell-testing-20200918.022351~1203^2~19 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=47e61c2b42b1391283f68f0ec4f77e9edae2b155;p=ceph-ci.git common: Add maybe_timespan For handling the common idiom of a zero timeout. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index f6185c88200..58b1550495d 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "include/ceph_assert.h" @@ -434,6 +435,9 @@ namespace ceph { return std::chrono::duration_cast( std::chrono::duration(d)); } + inline std::optional maybe_timespan(const double d) { + return d ? std::make_optional(make_timespan(d)) : std::nullopt; + } } std::ostream& operator<<(std::ostream& m, const timespan& t);