std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month)
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: years & dy ) noexcept ; |
(1) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
years
&
dy,
const std:: chrono :: year_month & ym ) noexcept ; |
(2) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: months & dm ) noexcept ; |
(3) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
months
&
dm,
const std:: chrono :: year_month & ym ) noexcept ; |
(4) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month
operator
-
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: years & dy ) noexcept ; |
(5) | (C++20以降) |
|
constexpr
std::
chrono
::
year_month
operator
-
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: months & dm ) noexcept ; |
(6) | (C++20以降) |
|
constexpr
std::
chrono
::
months
operator
-
(
const
std::
chrono
::
year_month
&
ym1,
const std:: chrono :: year_month & ym2 ) noexcept ; |
(7) | (C++20以降) |
期間が
std::chrono::years
と
std::chrono::months
の両方に変換可能な場合、
years
のオーバーロード
(1,2,5)
は、呼び出しが曖昧になる可能性がある場合に優先されます。
目次 |
戻り値
year_month
値
z
であり、
z
-
ym
==
dm
かつ
z.
ok
(
)
==
true
を満たす。
ym1. year ( ) - ym2. year ( ) + std:: chrono :: months ( int ( unsigned ( ym1. month ( ) ) ) -
int ( unsigned ( ym2. month ( ) ) ) )
注記
2つの
year_month
値の減算結果は
std::chrono::months
型の期間です。この期間単位は平均的なグレゴリオ暦の月の長さ(30.436875日)を表し、結果の期間は対象となる期間の実際の日数とは無関係です。例えば、
2017y
/
3
-
2017y
/
2
の結果は
std::
chrono
::
months
(
1
)
となりますが、2017年2月は28日間しか含まれていません。
例
#include <cassert> #include <chrono> int main() { auto ym{std::chrono::year(2021)/std::chrono::July}; ym = ym + std::chrono::months(14); assert(ym.month() == std::chrono::September); assert(ym.year() == std::chrono::year(2022)); ym = ym - std::chrono::years(3); assert(ym.month() == std::chrono::month(9)); assert(ym.year() == std::chrono::year(2019)); ym = ym + (std::chrono::September - std::chrono::month(2)); assert(ym.month() == std::chrono::April); assert(ym.year() == std::chrono::year(2020)); }
関連項目
月数または年数で
year_month
を変更する
(公開メンバ関数) |