std::chrono::year_month_weekday

std::chrono::year_month_weekday (연·월·N번째 요일 클래스)

특정 연도와 월의 n번째 요일을 나타내는 클래스예요. 필드 기반 시점 타입이고 분해능은 std::chrono::days예요. C++20의 chrono 달력 시스템에서 "매월 두 번째 금요일" 같은 날짜를 표현해요.

출처: cppreference

본문

<chrono> 헤더에 정의돼 있고, 특정 연도와 월의 n번째 요일을 나타내요.

class year_month_weekday;

필드 기반 시점 타입이고 분해능은 std::chrono::days예요. std::chrono::years·std::chrono::months 중심 산술이 직접 지원돼요. std::chrono::sys_days와의 암시적 변환 덕분에 std::chrono::days 중심 산술도 효율적으로 수행할 수 있어요. year_month_weekday는 TriviallyCopyable한 StandardLayoutType이에요.

멤버 함수:

  • 생성자: year_month_weekday를 만들 수 있어요.
  • operator+=, operator-=: 시점을 몇 달 또는 몇 년만큼 수정해요.
  • year(), month(), weekday(), index(), weekday_indexed(): 이 객체의 필드들에 접근해요.
  • operator sys_days, operator local_days: std::chrono::time_point로 변환해요.
  • ok: 이 객체가 유효한 날짜를 나타내는지 확인해요.

비멤버 함수:

  • operator== (C++20): 두 year_month_weekday 값을 비교해요.
  • operator+, operator- (C++20): year_month_weekday에 몇 년 또는 몇 달을 더하거나 빼요.
  • operator<< (C++20): year_month_weekday를 스트림에 출력해요.

헬퍼 클래스:

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

weekday_indexed는 "n번째 무슨 요일"을 나타내므로, 이 클래스는 예를 들어 "2023년 9월 두 번째 금요일" 같은 날짜를 표현하는 데 쓰여요. operator sys_days로 변환하면 실제 날짜를 얻을 수 있어요.

더 알아보기 (Learn more)

cppreference