Scroll to navigation

std::chrono::weekday::ok(3) C++ Standard Libary std::chrono::weekday::ok(3)

NAME

std::chrono::weekday::ok - std::chrono::weekday::ok

Synopsis


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()
{
for (const unsigned u : {0, 1, 6, 7, 8, 9}) {
const std::chrono::weekday wd{u};
std::cout
<< "u = " << u << ", wd = "
<< wd.c_encoding() // Monday is 1
<< (wd.ok() ? " is a valid weekday.\n"
: " is an invalid weekday!\n");
}
}

Output:


u = 0, wd = 0 is a valid weekday.
u = 1, wd = 1 is a valid weekday.
u = 6, wd = 6 is a valid weekday.
u = 7, wd = 0 is a valid weekday.
u = 8, wd = 8 is an invalid weekday!
u = 9, wd = 9 is an invalid weekday!

See also


c_encoding retrieves the stored weekday value
iso_encoding retrieves ISO 8601 weekday value
(public member function)

2022.07.31 http://cppreference.com