std::chrono::year_month:: operator+=, std::chrono::year_month:: operator-=
From cppreference.net
<
cpp
|
chrono
|
year month
|
constexpr
std::
chrono
::
year_month
&
operator + = ( const std:: chrono :: years & dy ) const noexcept ; |
(1) | (C++20부터) |
|
constexpr
std::
chrono
::
year_month
&
operator + = ( const std:: chrono :: months & dm ) const noexcept ; |
(2) | (C++20부터) |
|
constexpr
std::
chrono
::
year_month
&
operator - = ( const std:: chrono :: years & dy ) const noexcept ; |
(3) | (C++20부터) |
|
constexpr
std::
chrono
::
year_month
&
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> int main() { auto ym{std::chrono::day(1)/7/2023}; ym -= std::chrono::years{2}; assert(ym.month() == std::chrono::July); assert(ym.year() == std::chrono::year(2021)); ym += std::chrono::months{7}; assert(ym.month() == std::chrono::month(2)); assert(ym.year() == std::chrono::year(2022)); }
참고 항목
|
(C++20)
|
year_month
에 대한 산술 연산 수행
(함수) |