std::chrono...kday_indexed(3)

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

πŸ’– NAME πŸ’–

okay bestie, welcome to the C++ Standard Libary manual page for std::chrono...kday_indexed(3). The actual name is a whole mouthful:

  • std::chrono::month_weekday::month,std::chrono::month_weekday::weekday_indexed β€” std::chrono::month_weekday::month,std::chrono::month_weekday::weekday_indexed β€” yes, that's the same thing twice, and no, I didn't stutter πŸ’…

✨ Synopsis ✨

constexpr std::chrono::month month() const noexcept;

(1) (since C++20)

constexpr std::chrono::weekday_indexed weekday_indexed() const noexcept;

(2) (since C++20)

okay so these two are the accessors. They're both constexpr and noexcept, and both showed up in C++20, periodt. What do they do? They retrieve a copy of the month and weekday_indexed objects stored in *this. Like, not a reference, not a vibe, an actual copy, bestie. 🫢


🎁 Return value 🎁

  1. A copy of the std::chrono::month object stored in *this β€” it's giving "same month, fresh copy" 🌸
  2. A copy of the std::chrono::weekday_indexed object stored in *this β€” same weekday_indexed energy, copied out 😭

πŸ§ͺ Example πŸ§ͺ

// Run this code

#include <chrono>
#include <iostream>

int main()
{
    std::cout << std::boolalpha;

    auto mwdi{std::chrono::March/std::chrono::Friday[1]}; // 1st Friday in a March
    std::cout << (std::chrono::year_month_day{mwdi/2024} ==
                  std::chrono::year_month_day{std::chrono::March/1/2024})
                  << ' ';
    auto index = mwdi.weekday_indexed().index();
    auto weekday = mwdi.weekday_indexed().weekday();
    mwdi = {mwdi.month(), weekday[index + 4]}; // 5th Friday in a March
    std::cout << (std::chrono::year_month_day{mwdi/2024} ==
                  std::chrono::year_month_day{std::chrono::March/29/2024})
                  << '\n';
}

πŸ’» Output πŸ’»

true true

mwah πŸ’‹ this page came from http://cppreference.com, dated 2024.06.10 β€” that's the source/version and date combo, and that's the whole footer vibe. Go forth and accessorize, bestie πŸŽ€βœ¨

πŸ“¦ where this page comes from