std::chrono::clock_cast(3)
π std::chrono::clock_cast π
okay bestie, so this one is a function template from the C++ Standard Library β the manual name is std::chrono::clock_cast(3), and it's literally defined in the header <chrono>. she converts time points between clocks and she does it flawlessly. β¨
πΈ SYNOPSIS πΈ
Defined in header <chrono>:
template< class Dest, class Source, class Duration >
auto clock_cast( const std::chrono::time_point<Source, Duration>& t );
(since C++20) π«Ά
π DESCRIPTION π
So what she actually does: she takes the time point t of a clock Source and converts it into an equivalent time point of the clock Dest. And if she has to, she'll use std::chrono::system_clock and/or std::chrono::utc_clock as intermediaries β like, middlemen. no cap. π₯
Here's the whole decision tree, and honestly the way she picks is giving main character energy:
- If the expression
std::chrono::clock_time_conversion<Dest, Source>{}(t)is well-formed, she just returns the result of that expression. easy. iconic. β¨ - Otherwise, if at least one of the following two expressions is well-formed, then:
- If both expressions are well-formed, the conversion is ambiguous, and the program is ill-formed π (yes, that's a real problem, not a vibe)
- Otherwise, exactly one of the two expressions is well-formed, and the result of that expression is returned. slay.
std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t))std::chrono::clock_time_conversion<Dest, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, Source>{}(t))
- Otherwise, if at least one of the following two expressions is well-formed, then:
- If both expressions are well-formed, the conversion is ambiguous, and the program is ill-formed π (again β not cute, it's a hard error)
- Otherwise, exactly one of the two expressions is well-formed, and the result of that expression is returned. periodt.
std::chrono::clock_time_conversion<Dest, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t)))std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, Source>{}(t)))
- Otherwise, this function does not participate in overload resolution. she simply β¨ leaves β¨ π¦
bestie listen β those "both well-formed β ambiguous β ill-formed" bits are fr fr the important part. it's not a warning, the program is simply not valid. don't be that girl. π
π RETURN VALUE π
The result of the conversion, determined exactly as described above. that's it, that's the tea. π
π EXAMPLE π
This section is incomplete.
Reason: no example π (she's a mystery, iykyk)
β SEE ALSO β
clock_time_conversionβ traits class defining how to convert time points of one clock to another (C++20) (class template) π
π¦ CATEGORY π¦
- Todo:
no exampleπ
mwah π that's the whole page β sourced from http://cppreference.com, version 2024.06.10, and the page title is std::chrono::clock_cast(3). go forth and convert your clocks, 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