duration
Overview
Type safe representation of duration: the length of time that something lasts or continues, measured in seconds.
Declaration
struct duration_unit;
struct duration : _unspecified_base_type_
{
using base_type = _unspecified_base_type_;
using base_type::base_type;
using unit_type = duration_unit;
};
// Free functions
constexpr double as_double(duration d);
constexpr float as_float(duration d);
// Literals
inline namespace literals
{
constexpr duration operator "" _s(long double val);
constexpr duration operator "" _s(unsigned long long int val);
constexpr duration operator "" _ms(long double val);
constexpr duration operator "" _ms(unsigned long long int val);
constexpr duration operator "" _us(long double val);
constexpr duration operator "" _us(unsigned long long int val);
}
Expressions
In addition to valid expressions for Unit, duration
allows these expressions.
Notation
d
-
Object of type
duration
1.0
-
A floating point literal number.
1
-
An integer literal number.
Conversions
Expression | Semantics | Return Type |
---|---|---|
|
Convert duration to a |
|
|
Convert duration to a |
|
Literals
If you need to create duration
from numeric constants, it is preferrable to use duration
literals instead. Example:
auto d = 6_ms;
Expression | Semantics |
---|---|
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
Take note that 1.0
and 1
stand for any floating point, and integer numeric literals.
Unless you have a conflicting usage for the _s , _ms , and _us literals, it is generally safe to bring their namespace into scope using the using namespace cycfi::q::literals directive anywhere in a cpp file.
|