month_day_last

month_day_last (월의 마지막 날)

"어떤 월의 마지막 날"을 나타내는 타입이에요. 실제 일(day) 수를 즉시 알 수 없을 때 지연 표현을 담당해요. <chrono> 헤더, C++20부터.

출처: cppreference

본문

std::chrono::month_day_last는 특정 월의 마지막 날을 나타내요.

class month_day_last;
  • month(): 연관된 월을 돌려줘요.
  • ok(): 월이 유효한지 확인해요.
  • 비교 연산자(==, <=>)가 있어요.
  • operator/year_month_day_last 같은 복합 타입을 만들 수 있어요.
using namespace std::chrono;
auto mdl = February / last;   // 2월의 마지막 날

이 타입 자체는 "그 달의 마지막 날"이라는 의미만 담고, 실제 며칠인지는 윤년 등을 알 수 있는 더 큰 문맥(year_month_day_last)에서 계산돼요. 2월은 28/29일로 달라지니까요.

year_month_day_last == year_month_day 같은 비교나, 월말 기준 날짜 계산을 표현할 때 유용해요.

더 알아보기 (Learn more)

cppreference