std::chrono...kday_indexed(3)

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

πŸ¦‹ NAME πŸ¦‹

Bestie, you're on the std::chrono...kday_indexed(3) page, and the manual name is C++ Standard Libary β€” yes, that spelling, we are not fixing it, periodt. The icon herself is:

std::chrono::weekday_indexed::weekday_indexed β€” std::chrono::weekday_indexed::weekday_indexed

✨ Synopsis ✨

It constructs a weekday_indexed. There are two constructors, both (since C++20):

  1. weekday_indexed() = default; β€” constructor (1) (since C++20).
  2. constexpr weekday_indexed( const std::chrono::weekday& wd, unsigned index ) noexcept; β€” constructor (2) (since C++20).

The details, because we stay factual while being iconic:

  1. The default constructor leaves both the std::chrono::weekday and the index value uninitialized. Not me leaving things blank on purpose 😭.
  2. Constructs a weekday_indexed storing the weekday wd and the index index. The values held are unspecified if !wd.ok() || index > 7.
🚨 Vibe check: if !wd.ok() || index > 7, the values held are unspecified. That is the caveat, no cap β€” do not act like it's cute to ignore.

🌸 Notes 🌸

A more convenient way to construct a weekday_indexed is with weekday's operator[], i.e., wd[index]. That's the lowkey main character shortcut, iykyk. πŸ’…

πŸŽ€ Example πŸŽ€

// Run this code β€” literally, go run it:

#include <chrono>
#include <iostream>
using namespace std::chrono;

int main()
{
    constexpr auto third_friday = weekday_indexed(Friday, 3); // uses constructor (2)
    static_assert(third_friday == Friday[3]);

    weekday_indexed wdi = Tuesday[2]; // represents the 2nd Tuesday
    std::cout << year_month_day{ wdi / October / 2019y } << '\n';
}

πŸ’– Possible output πŸ’–

2019-10-08

πŸ‘‘ See also πŸ‘‘

  • operator[] β€” convenience syntax for constructing a weekday_indexed or weekday_last from this weekday (public member function of std::chrono::weekday).

And that's the whole page, bestie 🫢. Signing off from http://cppreference.com, dated 2024.06.10, with std::chrono...kday_indexed(3) energy. Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from