year_operator_arith_2

year_operator_arith_2 (year 산술 연산)

std::chrono::year에 대한 operator+, operator- 연산자예요. 연도에 연 수를 더하거나 빼요.

출처: cppreference

본문

std::chrono::year의 산술 연산자는 <chrono> 헤더에 정의되어 있어요. C++20부터 사용 가능해요.

constexpr std::chrono::year operator+( const std::chrono::year& y,
                                       const std::chrono::years& ys ) noexcept;

constexpr std::chrono::year operator-( const std::chrono::year& y,
                                       const std::chrono::years& ys ) noexcept;

연도 산술은 모듈로 400(레프릴리안 주기)로 처리돼요 (음수도 허용).

반환값 (Return value)

  • operator+yys를 더한 연도
  • operator-y에서 ys를 뺀 연도

예제 (Example)

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono;
    year y = year{2020} + years{5};
    std::cout << int(y) << '\n'; // 2025
}

더 알아보기 (Learn more)

cppreference