std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month_weekday)
year()
and
month()
as
std::
chrono
::
year_month
(
ymwd.
year
(
)
, ymwd.
month
(
)
)
+
dm
and the same
weekday()
and
index()
as
ymwd
.
For durations that are convertible to both
std::chrono::years
and
std::chrono::months
, the
years
overloads
(3,4,6)
are preferred if the call would otherwise be ambiguous.
Notes
Even if
ymwd.
ok
(
)
is
true
, the resulting
year_month_weekday
may not represent a valid date if
ymwd.
index
(
)
is
5
.
Example
#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; // First Wednesday in January, 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); // First Wednesday in July, 2025 std::cout << ymwdi << '\n'; assert(static_cast<std::chrono::year_month_day>(ymwdi) == std::chrono::July/2/2025); }
Output:
2021/Jan/Wed[1] 2026/Jan/Wed[1] 2025/Jul/Wed[1]