Namespaces
Variants

std::chrono::year:: year

From cppreference.net
year ( ) = default ;
(1) (C++20부터)
constexpr explicit year ( int y ) noexcept ;
(2) (C++20부터)

year 객체를 생성합니다.

1) 기본 생성자는 연도 값을 초기화하지 않은 상태로 둡니다.
2) 만약 y 가 범위 [ - 32767 , 32767 ] 내에 있다면, 연도 값 y 를 보유하는 year 객체를 생성합니다. 그렇지 않으면 보유하는 값은 지정되지 않습니다.

예제

#include <chrono>
#include <iostream>
int main()
{
    using namespace std::chrono;
    constexpr int leap_years = []
    {
        int count{};
        for (int i{year::min()}; i <= int{year::max()}; ++i)
            if (year{i}.is_leap()) // uses constructor (2)
                ++count;
        return count;
    } ();
    static_assert(15891 == leap_years);
    std::cout << "There are " << leap_years << " leap years in the range ["
              << int(year::min()) << ", " << int(year::max()) << "].\n";
}

출력:

There are 15891 leap years in the range [-32767, 32767].