year

year (연도)

달력의 연도(년)를 나타내는 타입이에요. <chrono> 헤더, C++20부터.

출처: cppreference

본문

std::chrono::year는 한 해를 나타내요. 정상 범위는 [-32767, 32767]이에요. int보다 좁은 16비트 정도의 부호 있는 정수로 연도를 표현해요.

class year;

멤버 함수 및 연산자:

  • (constructor), operator int(연도 값), ok()(범위 유효 여부).
  • operator++/--, operator+=/-=(연도 수 증감).
  • is_leap(): 윤년인지 확인.
  • 비교(==, <=>), yearmonth 결합(operator/).
using namespace std::chrono;
year y{2023};
bool leap = y.is_leap();          // false
auto ym = 2023y / June;           // year_month

operator/month/day와 결합해 완전한 날짜(year_month_day)를 만들 수 있어요. 윤년 계산이 필요해 is_leap()이 자주 쓰여요.

더 알아보기 (Learn more)

cppreference