std::chrono..._conversion(3)
π std::chrono::clock_time_conversion π
okay so bestie, welcome to the std::chrono..._conversion(3) page from the C++ Standard Libary π this one is all about std::chrono::clock_time_conversion, and it's lowkey the backstage matchmaker that tells your time points how to clock-shift. let's get into the vibe β¨
πΈ NAME πΈ
std::chrono::clock_time_conversion β literally std::chrono::clock_time_conversion, the trait bestie. iconic name, no notes π
β¨ Synopsis β¨
Defined in header <chrono>.
template< class Dest, class Source >
struct clock_time_conversion {};
(since C++20)
std::chrono::clock_time_conversion is a trait that specifies how to convert a std::chrono::time_point of the Source clock to that of the Dest clock. It does that by providing a const-callable operator() that accepts an argument of type std::chrono::time_point<Source, Duration> and returns a std::chrono::time_point<Dest, OtherDuration> that represents an equivalent point in time. The duration of the returned time point is computed from the source duration in a manner that varies for each specialization. iykyk π«Ά
clock_time_conversion is normally only used indirectly, via std::chrono::clock_cast β so most of the time it's just doing its little backstage thing while you live your life π¬
A program may specialize clock_time_conversion if at least one of the template parameters is a user-defined clock type.
The primary template is an empty struct. The standard defines the following specializations:
- (1) (since C++20)
template< class Clock >
struct clock_time_conversion<Clock, Clock>;
- (2) (since C++20)
template<>
struct clock_time_conversion<std::chrono::system_clock, std::chrono::system_clock>;
- (3) (since C++20)
template<>
struct clock_time_conversion<std::chrono::utc_clock, std::chrono::utc_clock>;
- (4) (since C++20)
template<>
struct clock_time_conversion<std::chrono::system_clock, std::chrono::utc_clock>;
- (5) (since C++20)
template<>
struct clock_time_conversion<std::chrono::utc_clock, std::chrono::system_clock>;
- (6) (since C++20)
template< class Clock >
struct clock_time_conversion<Clock, std::chrono::system_clock>;
- (7) (since C++20)
template< class Clock >
struct clock_time_conversion<std::chrono::system_clock, Clock>;
- (8) (since C++20)
template< class Clock >
struct clock_time_conversion<Clock, std::chrono::utc_clock>;
- (9) (since C++20)
template< class Clock >
struct clock_time_conversion<std::chrono::utc_clock, Clock>;
okay so the behavior breakdown, bestie:
- 1-3) Identity conversion:
operator()returns a copy of the argument. - 4,5) Conversions between
std::chrono::sys_timeandstd::chrono::utc_time:operator()callsstd::chrono::utc_clock::to_sysandstd::chrono::utc_clock::from_sys, respectively. - 6,7) Conversions to and from
std::chrono::sys_timewhenClocksupportsfrom_sysandto_sys:operator()callsClock::to_sysandClock::from_sys, respectively. - 8,9) Conversions to and from
std::chrono::utc_timewhenClocksupportsfrom_utcandto_utc:operator()callsClock::to_utcandClock::from_utc, respectively.
π οΈ Member functions π οΈ
Each specialization has an implicitly-declared default constructor, copy constructor, move constructor, copy assignment operator, move assignment operator, and destructor. yes, all of them, slay π
π std::chrono::clock_time_conversion::operator() π
- (1) β member of specialization (1):
template< class Duration >
std::chrono::time_point<Clock, Duration>
operator()( const std::chrono::time_point<Clock, Duration>& t ) const;
- (2) β member of specialization (2):
template< class Duration >
std::chrono::sys_time<Duration>
operator()( const std::chrono::sys_time<Duration> & t ) const;
- (3) β member of specialization (3):
template< class Duration >
std::chrono::utc_time<Duration>
operator()( const std::chrono::utc_time<Duration>& t ) const;
- (4) β member of specialization (4):
template< class Duration >
std::chrono::sys_time<Duration>
operator()( const std::chrono::utc_time<Duration>& t ) const;
- (5) β member of specialization (5):
template< class Duration >
std::chrono::utc_time<Duration>
operator()( const std::chrono::sys_time<Duration>& t ) const;
- (6) β member of specialization (6):
template< class Duration >
auto operator()( const std::chrono::sys_time<Duration>& t ) const
-> decltype(Clock::from_sys(t));
- (7) β member of specialization (7):
template< class Duration >
auto operator()( const std::chrono::time_point<SourceClock, Duration>& t ) const
-> decltype(Clock::to_sys(t));
- (8) β member of specialization (8):
template< class Duration >
auto operator()( const std::chrono::utc_time<Duration>& t ) const
-> decltype(Clock::from_utc(t));
- (9) β member of specialization (9):
template< class Duration >
auto operator()( const std::chrono::time_point<Clock, Duration>& t ) const
-> decltype(Clock::to_utc(t));
Converts the argument std::chrono::time_point to the destination clock. π°οΈβ¨
- 1-3) Identity conversion. Returns
tunchanged. - 4) Returns
std::chrono::utc_clock::to_sys(t). - 5) Returns
std::chrono::utc_clock::from_sys(t). - 6) Returns
Clock::from_sys(t). This overload participates in overload resolution only if the expressionClock::from_sys(t)is well-formed. The program is ill-formed ifClock::from_sys(t)does not returnstd::chrono::time_point<Clock, Duration>whereDurationis some valid specialization ofstd::chrono::duration. - 7) Returns
Clock::to_sys(t). This overload participates in overload resolution only if the expressionClock::to_sys(t)is well-formed. The program is ill-formed ifClock::to_sys(t)does not returnstd::chrono::sys_time<Duration>whereDurationis some valid specialization ofstd::chrono::duration. - 8) Returns
Clock::from_utc(t). This overload participates in overload resolution only if the expressionClock::from_utc(t)is well-formed. The program is ill-formed ifClock::from_utc(t)does not returnstd::chrono::time_point<Clock, Duration>whereDurationis some valid specialization ofstd::chrono::duration. - 9) Returns
Clock::to_utc(t). This overload participates in overload resolution only if the expressionClock::to_utc(t)is well-formed. The program is ill-formed ifClock::to_utc(t)does not returnstd::chrono::utc_time<Duration>whereDurationis some valid specialization ofstd::chrono::duration.
bestie, if you see ill-formed in there, that's not a cute vibe β it means the program is not valid. take it seriously π
π«Ά Parameters π«Ά
tβ time point to convert
π Return value π
The result of the conversion as described above:
- 1-3)
t. - 4)
std::chrono::utc_clock::to_sys(t). - 5)
std::chrono::utc_clock::from_sys(t). - 6)
Clock::from_sys(t). - 7)
Clock::to_sys(t). - 8)
Clock::from_utc(t). - 9)
Clock::to_utc(t).
π See also π
clock_castβ convert time points of one clock to another; (C++20) (function template)
mwah π this cutie came from source http://cppreference.com, with version/date 2024.06.10, and the page stamp is std::chrono..._conversion(3). that's the whole vibe, bye bestie! π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms