The <chrono>
header defines class steady_clock
that represents a monotonic clock - that is, the value of now()
never decreases as physical time increases. This class isn't marked as optional though, so what happens if the implementation can't implement it because it is running on a system with no monotonic time source?
Taking a look at the libstdc++ source, in the case of _GLIBCXX_USE_CLOCK_MONOTONIC
not being defined, steady_clock
is simply defined by:
typedef system_clock steady_clock;
system_clock
isn't necessarily steady though, so this may (and probably will) break the requirements of steady_clock
.
Is a conforming implementation of C++11 impossible on a system with no monotonic time source? Why not just make steady_clock
optional like the intX_t
types?
I suppose that such a system would be some kind of embedded system.
Well, such systems tomatoes can have freestanding implementations, which only require a minimal subset of the standard library. <chrono>
is not a part of that minimal subset.
This is defined in §17.6.1.3 Freestanding implementations [compliance]:
1 Two kinds of implementations are defined: hosted and freestanding (1.4). For a hosted implementation, this International Standard describes the set of available headers.
2 A freestanding implementation has an implementation-defined set of headers. This set shall include at least the headers shown in Table 16.
Table 16 contains the following headers: <ciso646>
, <cstddef>
, <cfloat>
, <limits>
, <climits>
, <cstdint>
, <cstdlib>
, <new>
, <typeinfo>
, <exception>
, <initializer_list>
, <cstdalign>
, <cstdarg>
, <cstdbool>
, <type_traits>
, and <atomic>
.
Note that this does not mean that such an implementation cannot provide a <chrono>
header with everything that can be implemented in it, but not the rest.
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