The C++ Draft par 20.12.7.3 reads:
high_resolution_clock
may be a synonym forsystem_clock
orsteady_clock
Of course this may mandates nothing but I wonder :
high_resolution_clock
to something other that a typedef ?system_clock
and high_resolution_clock
as well, defaulting to the typedef
solution once more ? The reason that specs have wording such as "may" and "can", and other vague words that allow for other possibilities comes from the wish by the spec writers not wanting to (unnecessarily) limit the implementation of a "better" solution of something.
Imagine a system where time in general is counted in seconds, and the system_clock
is just that - the system_clock::period
will return 1 second. This time is stored as a single 64-bit integer.
Now, in the same system, there is also a time in nano-seconds, but it's stored as a 128-bit integer. The resulting time-calculations are slightly more complex due to this large integer format, and for someone that only needs 1s precision for their time (in a system where a large number of calculations on time are made), you wouldn't want to have the extra penalty of using high_precision_clock
, when the system doesn't need it.
As to if there are such things in real life, I'm not sure. The key is that it's not a violation to the standard, if you care to implement it such.
Note that steady is very much a property of "what happens when the system changes time" (e.g. if the outside network has been down for a several days, and the internal clock in the system has drifted off from the atomic clock that the network time updates to). Using steady_clock
will guarantee that time doesn't go backwards or suddenly jumps forward 25 seconds all of a sudden. Likewise, there is no problem when there is a "leap second" or similar time adjustment in the computer system. On the other hand, a system_clock
is guaranteed to give you the correct new time if you give it a forward duration past a daylight savings time, or some such, where steady_clock
will just tick along hour after hour, regardless. So choosing the right one of those will affect the recording of your favourite program in the digital TV recorder - steady_clock
will record at the wrong time [my DTV recorder did this wrong a few years back, but they appear to have fixed it now].
system_clock
should also take into account the user (or sysadmin) changing the clock in the system, steady_clock
should NOT do so.
Again, high_resolution_clock
may or may not be steady
- it's up to the implementor of the C++ library to give the appropriate response to is_steady
.
In the 4.9.2 version of <chrono>
, we find this using high_resolution_clock = system_clock;
, so in this case it's a direct typedef
(by a different name). But the spec doesn't REQUIRE this.
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