std::chrono::month::ok
From cppreference.com
constexpr bool ok() const noexcept; |
(since C++20) | |
Checks if the month value stored in *this
is in the valid range, i.e., [1, 12].
Return value
true if the month value stored in *this
is in the range [1, 12]. Otherwise false.
Example
Run this code
#include <iostream> #include <chrono> int main() { std::chrono::month m1{6}; if (m1.ok()) { std::cout << "Month is valid\n"; } else { std::cout << "Month is invalid\n"; } std::chrono::month{0}.ok() ? std::cout << "Month is valid\n" : std::cout << "Month is invalid\n"; std::chrono::month{16}.ok() ? std::cout << "Month is valid\n" : std::cout << "Month is invalid\n"; }
Output:
Month is valid Month is invalid Month is invalid