std::chrono...nth_day::day(3)

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

πŸ¦‹ 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 πŸŽ€

  1. returns the stored std::chrono::month value. πŸ’–
  2. returns the stored std::chrono::day value. πŸ¦‹

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 is constexpr and noexcept β€” 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