std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month_weekday)
|
constexpr
std::
chrono
::
year_month_weekday
operator
+
(
const
std::
chrono
::
year_month_weekday
&
ymwd,
|
(1) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month_weekday
operator
+
(
const
std::
chrono
::
months
&
dm,
|
(2) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month_weekday
operator
+
(
const
std::
chrono
::
year_month_weekday
&
ymwd,
|
(3) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month_weekday
operator
+
(
const
std::
chrono
::
years
&
dy,
|
(4) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month_weekday
operator
-
(
const
std::
chrono
::
year_month_weekday
&
ymwd,
|
(5) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month_weekday
operator
-
(
const
std::
chrono
::
year_month_weekday
&
ymwd,
|
(6) | (seit C++20) |
year()
und
month()
wie
std::
chrono
::
year_month
(
ymwd.
year
(
)
, ymwd.
month
(
)
)
+
dm
und denselben
weekday()
und
index()
wie
ymwd
.
Für Zeitdauern, die sowohl in
std::chrono::years
als auch in
std::chrono::months
konvertierbar sind, werden die
years
Überladungen
(3,4,6)
bevorzugt, wenn der Aufruf andernfalls mehrdeutig wäre.
Hinweise
Selbst wenn
ymwd.
ok
(
)
true
ist, kann der resultierende
year_month_weekday
möglicherweise kein gültiges Datum darstellen, falls
ymwd.
index
(
)
5
ist.
Beispiel
#include <cassert> #include <chrono> #include <iostream> int main() { auto ymwdi{1/std::chrono::Wednesday[1]/2021}; std::cout << ymwdi << '\n'; ymwdi = std::chrono::years(5) + ymwdi; // Erster Mittwoch im Januar 2026 std::cout << ymwdi << '\n'; assert(static_cast<std::chrono::year_month_day>(ymwdi) == std::chrono::January/7/2026); ymwdi = ymwdi - std::chrono::months(6); // Erster Mittwoch im Juli 2025 std::cout << ymwdi << '\n'; assert(static_cast<std::chrono::year_month_day>(ymwdi) == std::chrono::July/2/2025); }
Ausgabe:
2021/Jan/Wed[1] 2026/Jan/Wed[1] 2025/Jul/Wed[1]