std::chrono..._day::month,(3)
β¨ std::chrono::year_month_day::year, std::chrono::year_month_day::month, std::chrono::year_month_day::day β¨
okay bestie so this is a page from the C++ Standard Library manual π
(yeah, that std::chrono..._day::month,(3) thing at the top is just the header, we're not doing that whole bit again). sit down, hydrate, let's get into it π«Ά
πΈ NAME πΈ
std::chrono::year_month_day::year, std::chrono::year_month_day::month, std::chrono::year_month_day::day β the three little accessor besties that pull the year, the month, and the day right back out of a year_month_day object π
β¨ Synopsis β¨
constexpr std::chrono::year year() const noexcept; (1) (since C++20)
constexpr std::chrono::month month() const noexcept; (2) (since C++20)
constexpr std::chrono::day day() const noexcept; (3) (since C++20)
so basically, these three are like the group chat of a year_month_day object β they retrieve the year, month and day values stored in this year_month_day object. periodt. π
Three separate functions, three separate receipts, all constexpr, all noexcept, all iconically C++20 and later π
π Return value π
- Returns the stored
std::chrono::yearvalue. ποΈ (yes, that's the whole sentence, she's lowkey simple but she ATE) - Returns the stored
std::chrono::monthvalue. πΈ - Returns the stored
std::chrono::dayvalue. β
likeβ¦ each one gives you exactly the piece it says on the tin, no cap π«Ά
π¦ Example π¦
// Run this code
#include <chrono>
int main()
{
constexpr std::chrono::year_month_day ymd{std::chrono::July/1/2021};
static_assert(ymd.year() == std::chrono::year(2021));
static_assert(ymd.month() == std::chrono::month(7));
static_assert(ymd.day() == std::chrono::day(1));
}
ok this example is literally the main character π€© you build a constexpr std::chrono::year_month_day out of std::chrono::July/1/2021, and then static_assert is out here doing a whole vibe check on all three getters β ymd.year() == std::chrono::year(2021), ymd.month() == std::chrono::month(7), ymd.day() == std::chrono::day(1). all three pass at compile time. slay πβ¨
ngl the static_asserts are the point here β they compile, or your program does not. no runtime drama, just pure compile-time confidence π
and that's the whole page, bestie! π§ source is http://cppreference.com, version date 2024.06.10, and the page itself is std::chrono..._day::month,(3). mwah π go forth and get your year, month and day ππ₯
π¦ 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