constexpr std::chrono::year_month_weekday& operator+=(const std::chrono::years& dy) const noexcept; | (1) | (since C++20) |
constexpr std::chrono::year_month_weekday& operator+=(const std::chrono::months& dm) const noexcept; | (2) | (since C++20) |
constexpr std::chrono::year_month_weekday& operator-=(const std::chrono::years& dy) const noexcept; | (3) | (since C++20) |
constexpr std::chrono::year_month_weekday& operator-=(const std::chrono::months& dm) const noexcept; | (4) | (since C++20) |
Modifies the time point *this
represents by the duration dy
or dm
.
*this = *this + dy;
*this = *this + dm;
*this = *this - dy;
*this = *this - dm;
Durations that are convertible to std::chrono::months
, but not std::chrono::years
, can be directly added to or subtracted from a year_month_weekday
. Durations convertible to std::chrono::years
cannot because such durations are also convertible to std::chrono::months
, resulting in an ambiguity:
using namespace std::chrono; using decades = duration<int, std::ratio_multiply<std::ratio<10>, years::period>>; using kilomonths = duration<int, std::ratio_multiply<std::kilo, months::period>>; auto ymwd = 2001y/April/Sunday[1]; ymwd += decades{1}; // error, ambiguous ymwd += kilomonths{1}; // OK
adds or subtracts a year_month_weekday and some number of years or months (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/chrono/year_month_weekday/operator_arith