std::chrono::weekday::ok(3)
π NAME π
bestie, welcome to the std::chrono::weekday::ok(3) page in the C++ Standard Libary manual. The star of the show is std::chrono::weekday::ok β and yes, the NAME line literally says std::chrono::weekday::ok - std::chrono::weekday::ok. iconic behavior, no notes. π
β¨ Synopsis β¨
constexpr bool ok() const noexcept; (since C++20)
okay so this lil const member checks if the weekday value stored in *this is in the valid range, i.e., [0, 6]. that's the whole vibe check. π¦
π Return value π
trueβ if the weekday value stored in*thisis in the range[0, 6].falseβ otherwise.
literally that's it. lowkey elegant. β¨
π¦ Example π¦
run this code, bestie β it's giving custom numpunct locale energy, and the truename/falsename are doing the absolute most π«Ά
// Run this code
#include <chrono>
#include <iomanip>
#include <iostream>
#include <locale>
#include <string>
struct weekday_ok : std::numpunct<char>
{
std::string do_truename() const override { return " (is valid weekday)"; }
std::string do_falsename() const override { return " (is not valid weekday)"; }
};
int main()
{
std::cout.imbue(std::locale(std::cout.getloc(), new weekday_ok));
std::cout << std::boolalpha;
for (const unsigned u : {0 /* Sun */, 1 /* Mon */, 6, 7 /* Sun */, 8, 9})
{
const std::chrono::weekday wd{u};
std::cout << "u: " << u << "; wd: " << wd.c_encoding() << wd.ok() << '\n';
}
}
π Output π
u: 0; wd: 0 (is valid weekday)
u: 1; wd: 1 (is valid weekday)
u: 6; wd: 6 (is valid weekday)
u: 7; wd: 0 (is valid weekday)
u: 8; wd: 8 (is not valid weekday)
u: 9; wd: 9 (is not valid weekday)
the way 7 wraps back around to 0? main character energy fr fr. πβ¨
π See also π
c_encodingβ retrieves the stored weekday valueiso_encodingβ retrieves ISO 8601 weekday value (public member function)
okay bye bestie, this page was brought to you by http://cppreference.com, dated 2024.06.10, for std::chrono::weekday::ok(3). slay and stay in range [0, 6] ππ§πΈ
π¦ 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