std::chrono...nth_day::day(3)
π¦ std::chrono::month_day::month, std::chrono::month_day::day π¦
okay so bestie, we're deep in the C++ Standard Library manual (C++ Standard Libary, yes that's how the page spells it, i don't make the rules π
) and today's main character is the humble month_day accessor duo. they're getters. they're constexpr. they're noexcept. they're literally the chillest little functions you will ever meet. π«Ά
β¨ NAME β¨
std::chrono::month_day::month, std::chrono::month_day::day β bestie, it's giving "same thing twice" energy:
std::chrono::month_day::month,std::chrono::month_day::day
that's it. that's the name. two accessors, one month_day object, zero drama. π
πΈ Synopsis πΈ
here's the whole vibe, copy-pasted straight from the source because i would never do you dirty:
constexpr std::chrono::month month() const noexcept; (1) (since C++20)
constexpr std::chrono::day day() const noexcept; (1) (since C++20)
(yes, both of them say (1) on the page β that's what it says, i'm just the messenger, don't come for me π)
what do they do? they retrieve the month and day values stored in this month_day object. that's the whole job. slay. π
π Return value π
- returns the stored
std::chrono::monthvalue. π - returns the stored
std::chrono::dayvalue. π¦
that's it. no surprises, no hidden side quests, no cap. β¨
π Example π
okay this is the part where you go "ohhh that's actually kinda cute" β look at this:
// Run this code
#include <chrono>
int main()
{
constexpr auto md{std::chrono::July/15};
static_assert(md.month() == std::chrono::month(7));
static_assert(md.day() == std::chrono::day(15));
}
the way that std::chrono::July/15 just builds a month_day out of thin air and then you can static_assert on it at compile time?? that's main character energy fr fr. md.month() gives you back std::chrono::month(7), md.day() gives you back std::chrono::day(15), and it all compiles before your code even runs. iconic. π₯
ngl the whole point of these two is that everything isconstexprandnoexceptβ so go wild, check your dates at compile time, live your best life. π
okay bye bestie, go read your calendar code, and remember β this little page came from cppreference.com, dated 2024.06.10, filed under std::chrono...nth_day::day(3) (the page title got truncated mid-word, she's doing her best π₯Ί). love u, hydrate, and may all your static_asserts pass on the first try. ππ§π«
π¦ 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