Namespaces
Variants

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

From cppreference.net
constexpr std:: chrono :: year_month operator + ( const std:: chrono :: year_month & ym,
const std:: chrono :: years & dy ) noexcept ;
(1) (C++20 이후)
constexpr std:: chrono :: year_month 연산자 + ( const std:: chrono :: years & dy,
const std:: chrono :: year_month & ym ) noexcept ;
(2) (C++20 이후)
constexpr std:: chrono :: year_month operator + ( const std:: chrono :: year_month & ym,
const std:: chrono :: months & dm ) noexcept ;
(3) (C++20 이후)
constexpr std:: chrono :: year_month operator + ( const std:: chrono :: months & dm,
const std:: chrono :: year_month & ym ) noexcept ;
(4) (C++20 이후)
constexpr std:: chrono :: year_month operator - ( const std:: chrono :: year_month & ym,
const std:: chrono :: years & dy ) noexcept ;
(5) (C++20 이후)
constexpr std:: chrono :: year_month 연산자 - ( const std:: chrono :: year_month & ym,
const std:: chrono :: months & dm ) noexcept ;
(6) (C++20 이후)
constexpr std:: chrono :: months operator - ( const std:: chrono :: year_month & ym1,
const std:: chrono :: year_month & ym2 ) noexcept ;
(7) (C++20 이후)
1,2) dy. count ( ) 년을 ym 에 추가합니다.
3,4) dm. count ( ) 개월을 ym 에 추가합니다.
5) dy. count ( ) 년을 ym 에서 뺍니다.
6) dm. count ( ) 개월을 ym 에서 뺍니다.
7) ym1 ym2 로 표현된 두 시간 지점 사이의 월(month) 차이를 반환합니다.

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

목차

반환값

1,2) std:: chrono :: year_month ( ym. year ( ) + dy, ym. month ( ) )
3,4) year_month z z - ym == dm 를 만족하고 z. ok ( ) == true 인 경우.
5) ym + - dy
6) ym + - dm
7)
ym1. year ( ) - ym2. year ( ) + std:: chrono :: months ( int ( unsigned ( ym1. month ( ) ) ) -
int ( unsigned ( ym2. month ( ) ) ) )

참고 사항

두 개의 year_month 값을 뺄셈한 결과는 std::chrono::months 타입의 기간입니다. 이 기간 단위는 평균 그레고리력 월 길이(30.436875일)를 나타내며, 결과 기간은 해당 기간의 실제 일수와 아무런 관계가 없습니다. 예를 들어, 2017y / 3 - 2017y / 2 의 결과는 std:: chrono :: months ( 1 ) 입니다. 비록 2017년 2월이 28일만 포함하더라도 말입니다.

예제

#include <cassert>
#include <chrono>
int main()
{
    auto ym{std::chrono::year(2021)/std::chrono::July};
    ym = ym + std::chrono::months(14);
    assert(ym.month() == std::chrono::September);
    assert(ym.year() == std::chrono::year(2022));
    ym = ym - std::chrono::years(3);
    assert(ym.month() == std::chrono::month(9));
    assert(ym.year() == std::chrono::year(2019));
    ym = ym + (std::chrono::September - std::chrono::month(2));
    assert(ym.month() == std::chrono::April);
    assert(ym.year() == std::chrono::year(2020));
}

참고 항목

월 또는 년 수만큼 year_month 를 수정합니다
(public member function)