ceph_assert(z >= signedspan::zero());
return std::chrono::duration_cast<timespan>(z);
}
+
+// detects presence of Clock::to_timespec() and from_timespec()
+template <typename Clock, typename = std::void_t<>>
+struct converts_to_timespec : std::false_type {};
+
+template <typename Clock>
+struct converts_to_timespec<Clock, std::void_t<decltype(
+ Clock::from_timespec(Clock::to_timespec(
+ std::declval<typename Clock::time_point>()))
+ )>> : std::true_type {};
+
+template <typename Clock>
+constexpr bool converts_to_timespec_v = converts_to_timespec<Clock>::value;
+
} // namespace ceph
#endif // COMMON_CEPH_TIME_H
// Time, since the templates are defined in std::chrono
-template<typename Clock, typename Duration>
+template<typename Clock, typename Duration,
+ typename std::enable_if_t<converts_to_timespec_v<Clock>>* = nullptr>
void encode(const std::chrono::time_point<Clock, Duration>& t,
ceph::bufferlist &bl) {
auto ts = Clock::to_timespec(t);
encode(ns, bl);
}
-template<typename Clock, typename Duration>
+template<typename Clock, typename Duration,
+ typename std::enable_if_t<converts_to_timespec_v<Clock>>* = nullptr>
void decode(std::chrono::time_point<Clock, Duration>& t,
bufferlist::iterator& p) {
uint32_t s;