The std::chrono
library relies, in part, on the concept of a Clock and a TrivialClock. I went through the standard, but I am still not sure about a few things:
Clock
and TrivialClock
, the fact that now
may throw for a Clock
, but does not for a TrivialClock
?clock::duration
required to be the same as clock::time_point::duration?
now
required to be a static function member, or not?References/quotes to the standard are welcome.
- Is the only difference between
Clock
andTrivialClock
, the fact that now may throw for aClock
, but does not for aTrivialClock
?
No. There are also more requirements on the member types of TrivialClock
. A clock with a const int
as its rep
is not a TrivialClock
, but it is a Clock
.
- Is
clock::duration
required to be the same asclock::time_point::duration
?
Yes. The two possible instantiations are std::time_point<clock>
, which has clock::duration
from the default parameter; or std::time_point<other_clock, clock::duration>
, which has it explicitly.
- Is
now
required to be a static function member, or not?
Not as far as I can tell, but people are likely to assume that it is. All that is required is for clock::now()
to be a valid expression, which returns a clock::time_point
. It could be a static functor.