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
.
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;
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;
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;
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).
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<Duration>,
where
Duration is a valid
chrono::duration specialization
. 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, Duration>,
where
Duration is a valid
chrono::duration specialization
. Returns: DestClock::from_sys(t).
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<Duration>,
where
Duration is a valid
chrono::duration specialization
. 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, Duration>,
where
Duration is a valid
chrono::duration specialization
. Returns: DestClock::from_utc(t). 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
.