std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month_day)
|
ヘッダーで定義
<chrono>
|
||
|
constexpr
std::
chrono
::
year_month_day
operator
+
(
const
std::
chrono
::
year_month_day
&
ymd,
const
std::
chrono
::
months
&
dm
|
(C++20以降) | |
|
constexpr
std::
chrono
::
year_month_day
operator
+
(
const
std::
chrono
::
months
&
dm,
const
std::
chrono
::
year_month_day
&
ymd
|
(C++20以降) | |
|
constexpr
std::
chrono
::
year_month_day
operator
+
(
const
std::
chrono
::
year_month_day
&
ymd,
const
std::
chrono
::
years
&
dy
|
(C++20以降) | |
|
constexpr
std::
chrono
::
year_month_day
operator
+
(
const
std::
chrono
::
years
&
dy,
const
std::
chrono
::
year_month_day
&
ymd
|
(C++20以降) | |
|
constexpr
std::
chrono
::
year_month_day
operator
-
(
const
std::
chrono
::
year_month_day
&
ymd,
const
std::
chrono
::
months
&
dm
|
(C++20以降) | |
|
constexpr
std::
chrono
::
year_month_day
operator
-
(
const
std::
chrono
::
year_month_day
&
ymd,
const
std::
chrono
::
years
&
dy
|
(C++20以降) | |
std::chrono::years
と
std::chrono::months
の両方に変換可能な期間型の場合、呼び出しが曖昧になる可能性があるときは
years
オーバーロード
(3,4,6)
が優先されます。
注記
ymd.
ok
(
)
が
true
であっても、
ymd.
day
(
)
が29、30、または31の場合、結果の
year_month_day
は有効な日付を表さない可能性があります。
例
#include <chrono> #include <iostream> int main() { std::cout << std::boolalpha; auto ymd{std::chrono::day(1)/std::chrono::July/2021}; ymd = ymd + std::chrono::months(4); std::cout << (ymd.month() == std::chrono::November) << ' ' << (ymd.year() == std::chrono::year(2021)) << ' '; ymd = ymd - std::chrono::years(10); std::cout << (ymd.month() == std::chrono::month(11)) << ' ' << (ymd.year() == std::chrono::year(2011)) << '\n'; }
出力:
true true true true