std::chrono::clock_cast(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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.
    1. std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t))
    2. 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.
    1. 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)))
    2. 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