std::chrono::month::ok(3)
β¨ NAME β¨
std::chrono::month::ok β bestie, it's literally the vibe check for your std::chrono::month π
This one lives in the C++ Standard Library and the whole page is giving "tiny function, big main character energy" π
β¨ Synopsis β¨
constexpr bool ok() const noexcept; (since C++20)
So what it does is check if the month value stored in *this is in the valid range, i.e., [1, 12]. That's it. That's the whole slay π
β¨ Return value β¨
- Returns
trueif the month value stored in*thisis in the range[1, 12]πΈ - Otherwise it returns
falseπ
No cap, that's the entire return situation.
β¨ Example β¨
// Run this code
#include <chrono>
#include <iostream>
int main()
{
for (const unsigned mm : {6u, 0u, 16U})
{
std::cout << mm << ": ";
const std::chrono::month m{mm};
m.ok() ? std::cout << "month is valid\n"
: std::cout << "month is invalid\n";
}
}
Output:
6: month is valid
0: month is invalid
16: month is invalid
See how 6 is out here thriving and valid, while 0 and 16 are lowkey not invited to the function? The range [1, 12] said what it said π«Ά
Quick reminder bestie: this isnoexceptandconstexpr, so it's not out here throwing surprises. It's just checking the month, periodt β¨
Okay that's the page!! Source: cppreference.com, dated 2024.06.10, and the manual is std::chrono::month::ok(3) π¦ Thanks for reading, ily, go validate your months responsibly ππ
π¦ 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