std::chrono::year::ok
From cppreference.com
constexpr bool ok() const noexcept; |
(since C++20) | |
Checks if the year value stored in *this
is in the valid range, i.e., [-32767, 32767].
Return value
true if the year value stored in *this
is in the range [-32767, 32767]. Otherwise false.
Example
Run this code
#include <iostream> #include <chrono> int main() { constexpr int iy1{2020}; std::cout << iy1 << " year is " << (std::chrono::year{iy1}.ok() ? "valid" : "invalid") << '\n'; constexpr int iy2{1 << 15}; std::cout << iy2 << " year is " << (std::chrono::year{iy2}.ok() ? "valid" : "invalid") << '\n'; }
Output:
2020 year is valid 32768 year is invalid