Spec-Zone.ru › C++

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

constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::years& dy ) const noexcept;
(1) (since C++20)
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::months& dm ) const noexcept;
(2) (since C++20)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::years& dy ) const noexcept;
(3) (since C++20)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::months& dm ) const noexcept;
(4) (since 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 <chrono>
#include <iostream>
using namespace std::chrono;
 
int main()
{
    auto ymwdl{August/Friday[last]/2022};
    std::cout << year_month_day{ymwdl} << '\n';
    ymwdl += months(2);
    std::cout << year_month_day{ymwdl} << '\n';
    ymwdl -= years(1); 
    std::cout << year_month_day{ymwdl} << '\n';
}

Вывод:

2022-08-26
2022-10-28
2021-10-29

См. также

operator+operator-
(C++20)
добавляет или вычитает year_month_weekday_last и некоторое количество лет или месяцев
(функция)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/chrono/year_month_weekday_last/operator_arith

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API