std::chrono::weekday::ok

From cppreference.com
< cpp‎ | chrono‎ | weekday
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Date and time utilities
(C++11)
(C++11)
Time of day
(C++20)



(C++20)(C++20)(C++20)(C++20)
Clocks
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Calendars
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time zones
(C++20)
(C++20)
(C++20)
(C++20)
C-style date and time
 
 
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

#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)