chrono::steady_clock consists of 4 member types: rep, period, duration, and timepoint.
chrono::steady_clock::duration is a chrono::duration<rep,period>.
chrono::steady_clock::period is a ratio.
How are the types of chrono::steady_clock::duration and chrono::steady_clock::period determined?
For example,
chrono::steady_clock::duration could be chrono::duration<int,period> where period is ratio<1,1000>
or
chrono::steady_clock::duration could be chrono::duration<double,period> where period is ratio<1,1000000>.
chrono::steady_clockconsists of 4 member types:rep,period,duration, andtimepoint.
chrono::stead_clock::durationis achrono::duration<rep,period>.chrono::steady_clock::periodis aratio.
Yes.
How are the types of
chrono::stead_clock::durationandchrono::steady_clock::perioddetermined?
They are somewhat implementation specific, but there do exist constraints and invariants among these types.
1. rep must be a pretty well-behaved arithmetic-like type. It must have a default constructor, copy constructor, copy assignment and it has non-surprising semantics, and doesn't throw exceptions. The de facto standard is that all steady_clock::rep are signed integral 64 bit types.
2. period is pretty much up in the air. That being said, VS, libstdc++ and libc++ all have steady_clock::period set to nano.
3. duration must have a very specific relationship to rep and period: is_same<duration, chrono::duration<rep, period>>{} is true_type. It doesn't matter much if you specify duration first and derive rep and period from that, or vice-versa. But the invariant must hold.
4. time_point shall be an instantiation of std::chrono::time_point with a duration of duration. It is unspecified what the time_point's clock is. However what type that clock is, it must have the same epoch as steady_clock. This is arguably a defect and should have the constraint that steady_clock::time_point::clock is steady_clock. The de facto standard is that this constraint holds.
The rep and period are unspecified by the standard. Each standard library implementation may choose their own. If the underlying timing calls they use have a precision of 100ns, choosing a period of std::ratio<100, 1000000000> seems like a good idea.
There are a few requirements those types must satisfy, but it's pretty much up to the implementation.
duration is always just based on rep and period... std::chrono::duration<rep, period>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With