std::chrono::day::ok(3)
π std::chrono::day::ok π
okay so bestie, we're on the std::chrono::day::ok(3) page from the C++ Standard Libary manual β yes, that spelling is iconic and we're keeping it β and this is your little vibe check for a std::chrono::day value. no cap π
β¨ NAME β¨
std::chrono::day::ok - std::chrono::day::ok
periodt, that's the name situation π
π¦ Synopsis π¦
constexpr bool ok() const noexcept; (since C++20)
The way this works: it checks if the day value stored in *this is in the valid range, i.e., [1, 31]. literally that's the assignment, and it's giving very demure, very mindful validation πΈ
π Return value π
It hands you true if the day value stored in *this is in the range [1, 31]. Otherwise? false. fr fr π
π Example π
// Run this code
#include <chrono>
using namespace std::chrono_literals;
constexpr std::chrono::day d0{00};
constexpr std::chrono::day d1{13};
constexpr std::chrono::day d2{42};
static_assert
(
d0 == 0d && !d0.ok() &&
d1 == 13d && d1.ok() &&
d2 == 42d && !d2.ok()
);
int main() {}
not me being obsessed with a static_assert that's literally checking 0d, 13d, and 42d β the range girlies get it β¨
π See also π
operator unsignedβ retrieves the stored day value (public member function). iykyk π«Ά
okay that's the whole page, bestie π source/version: http://cppreference.com, date: 2024.06.10 β std::chrono::day::ok(3) signing off with main character energy πβ¨
π¦ 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