Namespaces
Variants

std::chrono::year_month_weekday:: operator+=, std::chrono::year_month_weekday:: operator-=

From cppreference.net

constexpr std:: chrono :: year_month_weekday &
operator + = ( const std:: chrono :: years & dy ) const noexcept ;
(1) (C++20 이후)
constexpr std:: chrono :: year_month_weekday &
operator + = ( const std:: chrono :: months & dm ) const noexcept ;
(2) (C++20 이후)
constexpr std:: chrono :: year_month_weekday &
operator - = ( const std:: chrono :: years & dy ) const noexcept ;
(3) (C++20 이후)
constexpr std:: chrono :: year_month_weekday &
operator - = ( const std:: chrono :: months & dm ) const noexcept ;
(4) (C++20 이후)

시간점을 * this 이 나타내는 값을 지속 시간 dy 또는 dm 만큼 수정합니다.

1) 다음과 동일함 * this = * this + dy ; .
2) 다음과 동일함 * this = * this + dm ; .
3) 다음과 동일함: * this = * this - dy ; .
4) 다음과 동일함 * this = * this - dm ; .

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

예제

#include <cassert>
#include <chrono>
#include <iostream>
int main()
{
    auto ymwi{1/std::chrono::Wednesday[2]/2021};
    std::cout << ymwi << '\n';
    ymwi += std::chrono::years(5);
    std::cout << ymwi << '\n';
    assert(static_cast<std::chrono::year_month_day>(ymwi) ==
                       std::chrono::year(2026)/1/14);
    ymwi -= std::chrono::months(1);
    std::cout << ymwi << '\n';
    assert(static_cast<std::chrono::year_month_day>(ymwi) == 
                       std::chrono::day(10)/12/2025);
}

출력:

2021/Jan/Wed[2]
2026/Jan/Wed[2]
2025/Dec/Wed[2]

참고 항목

year_month_weekday 에 연수나 월수를 더하거나 빼기
(함수)