A type for storing a timeout duration.
A timeout can be zero, positive, or infinite. A default-constructed Timeout is infinite. The free functions isfinite() can be used to test for infinity:
using namespace std::literals;
Timeout()=default
Default-construct an infinite timeout.
friend bool isfinite(Timeout timeout) noexcept
Determine if the timeout has a finite duration.
Definition: Timeout.h:127
static constexpr Timeout infinity()
A constant to use for "infinite" timeout durations.
Definition: Timeout.h:124
For convenience, implicit conversion to floating-point types is supported, with an output in seconds:
double seconds =
Timeout{ 2500ms };
assert(seconds == 2.5);
assert(std::isinf(a));
Internally, a Timeout is stored as a std::chrono::duration with sub-second precision. The exact type used is made available as Timeout::Duration.
|
| Timeout ()=default |
| Default-construct an infinite timeout. More...
|
|
template<typename Rep , typename Period > |
constexpr | Timeout (std::chrono::duration< Rep, Period > duration) |
| Construct a Timeout from a std::chrono::duration (implicit for convenience). More...
|
|
template<typename FloatT , std::enable_if_t< std::is_floating_point< FloatT >::value, bool > = true> |
constexpr | Timeout (FloatT seconds) |
| Construct a Timeout from a floating-point value (only explicitly). More...
|
|
template<typename FloatT , std::enable_if_t< std::is_floating_point< FloatT >::value, bool > = true> |
| operator FloatT () const |
| Implicitly cast the timeout to a floating-point type. More...
|
|
template<typename DurationT , std::enable_if_t< std::is_arithmetic_v< typename DurationT::rep >, bool > = true> |
| operator DurationT () const |
| Explicitly cast the timeout to a std::chrono::duration type. More...
|
|
template<typename DurationT , std::enable_if_t< std::is_arithmetic_v< typename DurationT::rep >, bool > = true>
task::Timeout::operator DurationT |
( |
| ) |
const |
|
inline |
Explicitly cast the timeout to a std::chrono::duration type.
If the timeout is set to infinite, DurationT::max() is returned.
References isfinite, and timeout_.
template<typename FloatT , std::enable_if_t< std::is_floating_point< FloatT >::value, bool > = true>
task::Timeout::operator FloatT |
( |
| ) |
const |
|
inline |
Implicitly cast the timeout to a floating-point type.
Infinity is returned for an infinite timeout.
References isfinite, and timeout_.