Namespaces
Variants

std::chrono::year_month_day_last:: operator+=, std::chrono::year_month_day_last:: operator-=

From cppreference.net

constexpr std:: chrono :: year_month_day_last &
operator + = ( const std:: chrono :: years & dy ) const noexcept ;
(1) (начиная с C++20)
constexpr std:: chrono :: year_month_day_last &
operator + = ( const std:: chrono :: months & dm ) const noexcept ;
(2) (начиная с C++20)
constexpr std:: chrono :: year_month_day_last &
operator - = ( const std:: chrono :: years & dy ) const noexcept ;
(3) (начиная с C++20)
constexpr std:: chrono :: year_month_day_last &
operator - = ( const std:: chrono :: months & dm ) const noexcept ;
(4) (начиная с C++20)

Изменяет момент времени, который * this представляет, на продолжительность dy или dm .

1) Эквивалентно * this = * this + dy ; .
2) Эквивалентно * this = * this + dm ; .
3) Эквивалентно * this = * this - dy ; .
4) Эквивалентно * this = * this - dm ; .

Для длительностей, которые конвертируются как в std::chrono::years , так и в std::chrono::months , перегрузки years (1,3) имеют приоритет, если вызов иначе был бы неоднозначным.

Пример

#include <cassert>
#include <chrono>
int main()
{
    auto ymdl{11/std::chrono::last/2020};
    ymdl += std::chrono::years(15);
    assert(ymdl.day() == std::chrono::day(30));
    assert(ymdl.month() == std::chrono::November);
    assert(ymdl.year() == std::chrono::year(2035));
    ymdl -= std::chrono::months(6);
    assert(ymdl.day() == std::chrono::day(31));
    assert(ymdl.month() == std::chrono::May);
    assert(ymdl.year() == std::chrono::year(2035));
}

Смотрите также

добавляет или вычитает year_month_day_last и некоторое количество лет или месяцев
(функция)