29 Time library [time]

29.7 Clocks [time.clock]

29.7.10 time_point conversions [time.clock.cast]

29.7.10.1 Class template clock_time_conversion [time.clock.conv]

namespace std::chrono { template<class DestClock, class SourceClock> struct clock_time_conversion {}; }
clock_time_conversion serves as a trait which can be used to specify how to convert a source time_point of type time_point<SourceClock, Duration> to a destination time_point of type time_point<DestClock, Duration> via a specialization: clock_time_conversion<DestClock, SourceClock>.
A specialization of clock_time_conversion<DestClock, SourceClock> shall provide a const-qualified operator() that takes a parameter of type time_point<SourceClock, Duration> and returns a time_point<DestClock, OtherDuration> representing an equivalent point in time.
OtherDuration is a chrono​::​duration whose specialization is computed from the input Duration in a manner which can vary for each clock_time_conversion specialization.
A program may specialize clock_time_conversion if at least one of the template parameters is a user-defined clock type.
Several specializations are provided by the implementation, as described in [time.clock.cast.id], [time.clock.cast.sys.utc], [time.clock.cast.sys], and [time.clock.cast.utc].

29.7.10.2 Identity conversions [time.clock.cast.id]

template<class Clock> struct clock_time_conversion<Clock, Clock> { template<class Duration> time_point<Clock, Duration> operator()(const time_point<Clock, Duration>& t) const; };
template<class Duration> time_point<Clock, Duration> operator()(const time_point<Clock, Duration>& t) const;
Returns: t.
template<> struct clock_time_conversion<system_clock, system_clock> { template<class Duration> sys_time<Duration> operator()(const sys_time<Duration>& t) const; };
template<class Duration> sys_time<Duration> operator()(const sys_time<Duration>& t) const;
Returns: t.
template<> struct clock_time_conversion<utc_clock, utc_clock> { template<class Duration> utc_time<Duration> operator()(const utc_time<Duration>& t) const; };
template<class Duration> utc_time<Duration> operator()(const utc_time<Duration>& t) const;
Returns: t.

29.7.10.3 Conversions between system_clock and utc_clock [time.clock.cast.sys.utc]

template<> struct clock_time_conversion<utc_clock, system_clock> { template<class Duration> utc_time<common_type_t<Duration, seconds>> operator()(const sys_time<Duration>& t) const; };
template<class Duration> utc_time<common_type_t<Duration, seconds>> operator()(const sys_time<Duration>& t) const;
Returns: utc_clock​::​from_sys(t).
template<> struct clock_time_conversion<system_clock, utc_clock> { template<class Duration> sys_time<common_type_t<Duration, seconds>> operator()(const utc_time<Duration>& t) const; };
template<class Duration> sys_time<common_type_t<Duration, seconds>> operator()(const utc_time<Duration>& t) const;
Returns: utc_clock​::​to_sys(t).

29.7.10.4 Conversions between system_clock and other clocks [time.clock.cast.sys]

template<class SourceClock> struct clock_time_conversion<system_clock, SourceClock> { template<class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_sys(t)); };
template<class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_sys(t));
Constraints: SourceClock​::​to_sys(t) is well-formed.
Mandates: SourceClock​::​to_sys(t) returns a sys_time<Duration2> for some type Duration2 ([time.point.general]).
Returns: SourceClock​::​to_sys(t).
template<class DestClock> struct clock_time_conversion<DestClock, system_clock> { template<class Duration> auto operator()(const sys_time<Duration>& t) const -> decltype(DestClock::from_sys(t)); };
template<class Duration> auto operator()(const sys_time<Duration>& t) const -> decltype(DestClock::from_sys(t));
Constraints: DestClock​::​from_sys(t) is well-formed.
Mandates: DestClock​::​from_sys(t) returns a time_point<DestClock, Duration2> for some type Duration2 ([time.point.general]).
Returns: DestClock​::​from_sys(t).

29.7.10.5 Conversions between utc_clock and other clocks [time.clock.cast.utc]

template<class SourceClock> struct clock_time_conversion<utc_clock, SourceClock> { template<class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_utc(t)); };
template<class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_utc(t));
Constraints: SourceClock​::​to_utc(t) is well-formed.
Mandates: SourceClock​::​to_utc(t) returns a utc_time<Duration2> for some type Duration2 ([time.point.general]).
Returns: SourceClock​::​to_utc(t).
template<class DestClock> struct clock_time_conversion<DestClock, utc_clock> { template<class Duration> auto operator()(const utc_time<Duration>& t) const -> decltype(DestClock::from_utc(t)); };
template<class Duration> auto operator()(const utc_time<Duration>& t) const -> decltype(DestClock::from_utc(t));
Constraints: DestClock​::​from_utc(t) is well-formed.
Mandates: DestClock​::​from_utc(t) returns a time_point<DestClock, Duration2> for some type Duration2 ([time.point.general]).
Returns: DestClock​::​from_utc(t).

29.7.10.6 Function template clock_cast [time.clock.cast.fn]

template<class DestClock, class SourceClock, class Duration> auto clock_cast(const time_point<SourceClock, Duration>& t);
Constraints: At least one of the following clock time conversion expressions is well-formed:
  • clock_time_conversion<DestClock, SourceClock>{}(t)
  • clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t))
  • clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t))
  • clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t)))
  • clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t)))
A clock time conversion expression is considered better than another clock time conversion expression if it involves fewer operator() calls on clock_time_conversion specializations.
Mandates: Among the well-formed clock time conversion expressions from the above list, there is a unique best expression.
Returns: The best well-formed clock time conversion expression in the above list.