From 47e61c2b42b1391283f68f0ec4f77e9edae2b155 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Wed, 16 Aug 2017 20:42:00 -0400 Subject: [PATCH] common: Add maybe_timespan For handling the common idiom of a zero timeout. Signed-off-by: Adam C. Emerson --- src/common/ceph_time.h | 4 ++++ 1 file changed, 4 insertions(+) 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); -- 2.39.5