std::chrono...weekday_last(3)

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

std::chrono...weekday_last(3) πŸ’…

okay so bestie, you've landed on the std::chrono...weekday_last(3) page from the C++ Standard Libary manual (that's the manual name, fr fr). We're talking about the constructor with main character energy: std::chrono::weekday_last::weekday_last. Let's get into it. πŸ¦‹

✨ NAME ✨

  • std::chrono::weekday_last::weekday_last β€” yep, that's the NAME, and the description is also std::chrono::weekday_last::weekday_last. It's giving very "I am the page and the constructor" energy. πŸ‘‘

🌸 Synopsis 🌸

Here's the exact signature, no cap:

constexpr explicit weekday_last( const std::chrono::weekday& wd )
(since C++20)
noexcept;

It's constexpr, it's explicit, it takes const std::chrono::weekday& wd, and it's noexcept;. Constructs a weekday_last object storing the weekday wd. ✨

πŸ’‘ Notes πŸ’‘

okay so there's a more convenient way to construct a weekday_last: use weekday's operator[], i.e., wd[std::chrono::last]. That's the shortcut, iykyk. πŸ’–

πŸŽ€ Example πŸŽ€

The original has this little // Run this code cue:

// Run this code

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

int main()
{
    const year_month_day ymd{floor<days>(system_clock::now())};
    const weekday_last wdl{Sunday[last]}; // A last Sunday of a month
    const year_month_day last_sun{ymd.year() / ymd.month() / wdl};

    std::cout << "The last Sunday of current month falls on "
              << (int)last_sun.year() << '/'
              << (unsigned)last_sun.month() << '/'
              << (unsigned)last_sun.day() << '\n';
}

slay. πŸ’–

Possible output:

The last Sunday of current month falls on 2021/9/26

And that's the whole vibe.


cute little sign-off: this page is from http://cppreference.com, dated 2024.06.10, and it's the std::chrono...weekday_last(3) page. bye bestie, go construct something iconic πŸ«ΆπŸ’…

πŸ“¦ where this page comes from