month_operator_arith_2

month_operator_arith_2 (month 산술 연산)

std::chrono::month에 대한 operator+, operator- 연산자예요. 월에 개월 수를 더하거나 빼고, 두 month 사이의 차이를 계산해요.

출처: cppreference

본문

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

constexpr std::chrono::month operator+( const std::chrono::month& m,
                                        const std::chrono::months& ms ) noexcept;

constexpr std::chrono::months operator-( const std::chrono::month& x,
                                         const std::chrono::month& y ) noexcept;

개월 수의 산술은 모듈로 12 연산으로 처리돼요 (음수도 허용). 예를 들어 11월 + 3개월 = 2월이에요.

반환값 (Return value)

  • operator+mms를 더한 월 (모듈로 12)
  • operator- — 두 month xy의 차이(개월 수)

예제 (Example)

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono;
    month m = month{11} + months{3};
    std::cout << unsigned(m) << '\n'; // 2
}

더 알아보기 (Learn more)

cppreference