Namespaces
Variants

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

From cppreference.net
constexpr std:: chrono :: year operator + ( const std:: chrono :: year & y,
const std:: chrono :: years & ys ) noexcept ;
(1) (C++20부터)
constexpr std:: chrono :: year operator + ( const std:: chrono :: years & ys,
const std:: chrono :: year & y ) noexcept ;
(2) (C++20부터)
constexpr std:: chrono :: year operator - ( const std:: chrono :: year & y,
const std:: chrono :: years & ys ) noexcept ;
(3) (C++20부터)
constexpr std:: chrono :: years operator - ( const std:: chrono :: year & y1,
const std:: chrono :: year & y2 ) noexcept ;
(4) (C++20부터)
1,2) ys. count ( ) 년을 y 에 추가합니다.
3) ys. count ( ) 년을 y 에서 뺍니다.
4) y1 y2 사이의 연도 차이를 반환합니다.

목차

반환값

1,2) std:: chrono :: year ( int ( y ) + ys. count ( ) )
3) std:: chrono :: year ( int ( y ) - ys. count ( ) )
4) std:: chrono :: years ( int ( y1 ) - int ( y2 ) )

참고 사항

(1-3)의 결과 연도 값이 (1-3) 범위 [ - 32767 , 32767 ] 를 벗어나는 경우, 실제 저장되는 값은 지정되지 않습니다.

두 개의 year 값을 뺀 결과는 std::chrono::years 타입의 기간입니다. 이 기간 단위는 평균 그레고리력 연도의 길이를 나타내며, 결과 기간은 피연산자로 표현된 특정 연도의 일수와 아무런 관계가 없습니다. 예를 들어, 2018y - 2017y 의 결과는 std:: chrono :: years ( 1 ) 로, 365일이 아닌 365.2425일을 나타냅니다.

예제

#include <cassert>
#include <chrono>
int main()
{
    std::chrono::year y{2020};
    y = std::chrono::years(12) + y; // 오버로드 (2): duration + time point
    assert(y == std::chrono::year(2032));
    y = y - std::chrono::years(33); // 오버로드 (3): time point - duration
    assert(y == std::chrono::year(1999));
    // y = std::chrono::years(33) - y; // 지원되지 않음: duration - time point
    using namespace std::chrono;
    constexpr std::chrono::years ys = 2025y - 2020y; // 오버로드 (4)
    static_assert(ys == std::chrono::years(5));
}

참고 항목

월을 증가 또는 감소시킴
( std::chrono::month 의 public member function)
개월 수를 더하거나 뺌
( std::chrono::month 의 public member function)