month_weekday

month_weekday (특정 월의 n번째 요일)

"어떤 월의 몇 번째 무슨 요일"을 나타내는 타입이에요. 예를 들어 "5월의 두 번째 일요일"을 표현해요. <chrono> 헤더, C++20부터.

출처: cppreference

본문

std::chrono::month_weekday는 월(month)과 요일·차수(weekday_indexed)의 조합이에요.

class month_weekday;
  • month()weekday_indexed() 멤버를 제공해요.
  • ok(): 조합이 유효한지 확인해요.
  • 비교 연산자가 있어요.
  • operator/로 생성할 수 있어요.
using namespace std::chrono;
auto mwd = May / Sunday[2];   // 5월의 두 번째 일요일

Sunday[2][2]가 "두 번째"를 뜻하는 weekday_indexed예요. 이 조합은 year_month_weekday 등과 함께 "매년 N번째 요일" 같은 규칙적인 날짜 표현에 쓰여요.

예: 어머니의 날은 5월 둘째 일요일인데, 그런 요일 기반 날짜를 타입으로 표현할 때 유용해요.

더 알아보기 (Learn more)

cppreference