std::chrono::year_month

std::chrono::year_month (연·월 클래스)

특정 연도의 특정 달을 나타내되, 일(day)은 지정하지 않는 클래스예요. 필드 기반 시점 타입으로, 분해능은 std::chrono::months예요. C++20의 chrono 달력 시스템에서 연·월 조합을 다뤄요.

출처: cppreference

본문

<chrono> 헤더에 정의돼 있고, 특정 연도의 특정 달을 나타내며 일은 지정하지 않아요.

class year_month;

필드 기반(field-based) 시점 타입이고, 분해능은 std::chrono::months예요. year_month는 TriviallyCopyable한 StandardLayoutType이에요.

멤버 함수:

  • 생성자: year_month를 만들 수 있어요.
  • year(), month(): 저장된 연과 월을 접근해요.
  • operator+=, operator-=: year_month를 몇 달 또는 몇 년만큼 수정해요.
  • ok: 이 year_month가 유효한지 확인해요.

비멤버 함수:

  • operator==, operator<=> (C++20): 두 year_month 값을 비교해요.
  • operator+, operator- (C++20): year_month에 산술 연산을 수행해요.
  • operator<< (C++20): year_month를 스트림에 출력해요.
  • from_stream (C++20): 제공된 형식에 따라 스트림에서 year_month를 파싱해요.

헬퍼 클래스:

  • std::formatter<std::chrono::year_month> (C++20): year_month 포맷 지원.
  • std::hash<std::chrono::year_month> (C++26): std::chrono::year_month 해시 지원.

year_month는 연도·월 조합만을 다루므로, 특정 날짜를 나타내려면 year_month_day에 일(day)을 추가해 구성해요. 예를 들어 2023y / February처럼 연산자로 만들 수 있고, month() 멤버로 월을 얻어요.

더 알아보기 (Learn more)

cppreference