std::chrono::year::ok

Checks if the year value stored in *this is in the valid range, i.e., [-32767,32767].

# Declarations

constexpr bool ok() const noexcept;

(since C++20)

# Return value

true if the year value stored in *this is in the range [-32767,32767]. Otherwise false.

# Example

#include <chrono>
#include <iomanip>
#include <iostream>
 
int main()
{
    std::cout << "input year │ internal value │ ok()\n" << std::boolalpha;
 
    for (const int i : {2020, 0x8000, 0x8001, 0xFFFF, 0x18000})
    {
        const std::chrono::year y{i};
        std::cout << std::setw(10) << i << " │ "
                  << std::setw(14) << static_cast<int>(y) << " │ "
                  << y.ok() << '\n';
    }
}