Namespaces
Variants

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

From cppreference.net
헤더에 정의됨 <chrono>
(C++20부터)
(C++20부터)
constexpr std:: chrono :: year_month_day operator + ( const std:: chrono :: year_month_day & ymd,

const std:: chrono :: years & dy

) noexcept ;
(C++20부터)
constexpr std:: chrono :: year_month_day operator + ( const std:: chrono :: years & dy,

const std:: chrono :: year_month_day & ymd

) noexcept ;
(C++20부터)
(C++20부터)
constexpr std:: chrono :: year_month_day operator - ( const std:: chrono :: year_month_day & ymd,

const std:: chrono :: years & dy

) noexcept ;
(C++20부터)
1,2) dm. count ( ) 개월을 ymd 가 나타내는 날짜에 더합니다. 결과는 ymd 와 동일한 day ( ) 를 가지며, std:: chrono :: year_month ( ymd. year ( ) , ymd. month ( ) ) + dm 와 동일한 year ( ) month ( ) 를 가집니다.
3,4) dy. count ( ) 년을 ymd 가 나타내는 날짜에 더합니다. 결과는 std:: chrono :: year_month_day ( ymd. year ( ) + dy, ymd. month ( ) , ymd. day ( ) 와 동일합니다.
5) ymd 가 나타내는 날짜에서 dm. count ( ) 개월을 뺍니다. ymd + - dm 와 동일합니다.
6) ymd 가 나타내는 날짜에서 dy. count ( ) 년을 뺍니다. ymd + - dy 와 동일합니다.

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

참고 사항

ymd. ok ( ) true 라 하더라도, 결과로 생성된 year_month_day 가 유효하지 않은 날짜를 나타낼 수 있습니다. 특히 ymd. day ( ) 가 29, 30, 또는 31일 경우에 그러합니다.

예제

#include <chrono>
#include <iostream>
int main()
{
    std::cout << std::boolalpha;
    auto ymd{std::chrono::day(1)/std::chrono::July/2021};
    ymd = ymd + std::chrono::months(4);
    std::cout << (ymd.month() == std::chrono::November) << ' '
              << (ymd.year() == std::chrono::year(2021)) << ' ';
    ymd = ymd - std::chrono::years(10);
    std::cout << (ymd.month() == std::chrono::month(11)) << ' '
              << (ymd.year() == std::chrono::year(2011)) << '\n';
}

출력:

true true true true