std::chrono::weekday::ok
From cppreference.com
constexpr bool ok() const noexcept; |
(since C++20) | |
Checks if the weekday value stored in *this
is in the valid range, i.e., [0, 6].
Return value
true if the weekday value stored in *this
is in the range [0, 6]. Otherwise false.
Example
Run this code
#include <iostream> #include <chrono> int main() { std::chrono::weekday wd1{1}; // Monday is 1 std::cout << wd1.c_encoding(); if (wd1.ok()) { std::cout << " is a valid weekday.\n"; } else { std::cout << " is an invalid weekday!\n"; } std::chrono::weekday wd2{42}; std::cout << wd2.c_encoding() << (wd2.ok() ? " is a valid weekday.\n" : " is an invalid weekday!\n"); }
Output:
1 is a valid weekday. 42 is an invalid weekday!
See also
retrieves the stored weekday value retrieves ISO 8601 weekday value (public member function) |