std::chrono...ay_last::ok(3)
π std::chrono::year_month_weekday_last::ok
okay so bestie, welcome to the std::chrono...ay_last::ok(3) page β that's the C++ Standard Library manual, and today's main character is a little member function that just wants to know if your date is valid π
β¨ NAME β¨
std::chrono::year_month_weekday_last::ok β std::chrono::year_month_weekday_last::ok (yes the name is the same twice, it's giving "I said what I said" π)
πΈ SYNOPSIS πΈ
constexpr bool ok() const noexcept;
(since C++20) β¨
π¦ DESCRIPTION π¦
Bestie, this one's literally a vibe check for your date π It checks if this object represents a valid date.
And here's the tea π: since a year_month_weekday_last represents the last weekday of a particular month, it's valid as long as the year, month and weekday are all valid. That's it, that's the whole check β all three have to pass their own vibe check or the whole thing flops π
π₯ RETURN VALUE π₯
year().ok() && month().ok() && weekday().ok()
It literally just ANDs all three together β year().ok(), month().ok(), and weekday().ok() β and returns that π No cap, it's that simple.
π EXAMPLE π
Run this code π
#include <cassert>
#include <chrono>
using namespace std::chrono;
int main()
{
auto ymwdl{Tuesday[last]/11/2020};
assert(ymwdl.ok());
ymwdl = Tuesday[last]/-2/2021;
assert(!ymwdl.ok());
ymwdl += months(0); // Normalize month
assert(ymwdl.ok());
}
So the way this works π β Tuesday[last]/11/2020 is a whole mood and passes the vibe check β
. Then Tuesday[last]/-2/2021 with that cursed negative month? Not ok, the assert fires, iconic behaviour honestly π. Then ymwdl += months(0); normalizes the month and suddenly we're back to valid again. Character development π§β¨
source: http://cppreference.com Β· version/date: 2024.06.10
ok that's the whole page bestie, mwah π β stay valid, stay normalized, and remember: assert(ymwdl.ok()) is self care π«Άπππβ
π¦ 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