std::chrono::day::ok(3)

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

πŸ’… 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