std::chrono...ar_month::ok(3)

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

πŸ’– NAME πŸ’–

Bestie, welcome to the C++ Standard Libary page for the std::chrono...ar_month::ok(3) manpage πŸ’…βœ¨. The star of the show is std::chrono::year_month::ok - std::chrono::year_month::ok, and yes, that’s the whole name. Iconic behavior only. 🫢

🌸 Synopsis 🌸

constexpr bool ok() const noexcept;

since C++20 ✨

This is the check that asks: are the year and month values stored in this object valid? That’s the entire assignment, no cap. πŸ¦‹

⭐ Return value ⭐

year().ok() && month().ok()

It’s literally that expression β€” both parts gotta pass, or it’s a no from me πŸ˜­πŸ’€.

πŸŽ€ Example πŸŽ€

// Run this code

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

int main()
{
    constexpr std::chrono::year_month ym1{3030y, std::chrono::July};
    static_assert(ym1.ok());

    constexpr std::chrono::year_month ym2{std::chrono::year(2020)/16};
    static_assert(!ym2.ok());
}

ym1 is valid, so static_assert(ym1.ok()); is slaying ✨. ym2 is built with std::chrono::year(2020)/16 and is not valid, so static_assert(!ym2.ok()); also holds. Periodt. πŸ‘‘


Final sign-off, bestie 🫢: source/version/date β€” http://cppreference.com Β· 2024.06.10 Β· std::chrono...ar_month::ok(3) πŸ’–πŸ¦‹

πŸ“¦ where this page comes from