std::chrono::year_month_day_last:: operator+=, std::chrono::year_month_day_last:: operator-=
From cppreference.net
<
cpp
|
chrono
|
year month day last
|
constexpr
std::
chrono
::
year_month_day_last
&
operator + = ( const std:: chrono :: years & dy ) const noexcept ; |
(1) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month_day_last
&
operator + = ( const std:: chrono :: months & dm ) const noexcept ; |
(2) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month_day_last
&
operator - = ( const std:: chrono :: years & dy ) const noexcept ; |
(3) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month_day_last
&
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 ymdl{11/std::chrono::last/2020}; ymdl += std::chrono::years(15); assert(ymdl.day() == std::chrono::day(30)); assert(ymdl.month() == std::chrono::November); assert(ymdl.year() == std::chrono::year(2035)); ymdl -= std::chrono::months(6); assert(ymdl.day() == std::chrono::day(31)); assert(ymdl.month() == std::chrono::May); assert(ymdl.year() == std::chrono::year(2035)); }
関連項目
|
(C++20)
|
year_month_day_last
と年数または月数を加算または減算する
(関数) |