Namespaces
Variants

std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month_day_last)

From cppreference.net
헤더에 정의됨 <chrono>
(C++20부터)
(C++20 이후)
(C++20 이후)
(C++20 이후)
(C++20 이후)
(C++20 이후)
1,2) dm. count ( ) 개월을 ymdl 이 나타내는 날짜에 더합니다. 결과는 year() month() std:: chrono :: year_month ( ymdl. year ( ) , ymdl. month ( ) ) + dm 와 동일합니다.
3,4) dy. count ( ) 년을 ymdl 이 나타내는 날짜에 더합니다. 결과는 std:: chrono :: year_month_day_last ( ymdl. year ( ) + dy, ymdl. month_day_last ( ) ) 와 동일합니다.
5) 현재 날짜에서 dm. count ( ) 개월을 뺍니다. 다음 표현과 동일합니다: ymdl + - dm .
6) ymdl 이 나타내는 날짜에서 dy. count ( ) 년을 뺍니다. ymdl + - dy 와 동일합니다.

std::chrono::years std::chrono::months 모두로 변환 가능한 지속 시간의 경우, 호출이 모호해질 수 있는 상황에서는 years 오버로드 (3,4,6) 가 우선적으로 선택됩니다.

예제

#include <cassert>
#include <chrono>
#include <iostream>
int main()
{
    auto ymdl{11/std::chrono::last/2020};
    std::cout << ymdl << '\n';
    ymdl = std::chrono::years(10) + ymdl;
    std::cout << ymdl << '\n';
    assert(ymdl == std::chrono::day(30)/
                   std::chrono::November/
                   std::chrono::year(2030));
    ymdl = ymdl - std::chrono::months(6);
    std::cout << ymdl << '\n';
    assert(ymdl == std::chrono::day(31)/
                   std::chrono::May/
                   std::chrono::year(2030));
}

출력:

2020/Nov/last
2030/Nov/last
2030/May/last