Namespaces
Variants

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

From cppreference.net

constexpr std:: chrono :: year_month_weekday_last &
operator + = ( const std:: chrono :: years & dy ) const noexcept ;
(1) (seit C++20)
constexpr std:: chrono :: year_month_weekday_last &
operator + = ( const std:: chrono :: months & dm ) const noexcept ;
(2) (seit C++20)
constexpr std:: chrono :: year_month_weekday_last &
operator - = ( const std:: chrono :: years & dy ) const noexcept ;
(3) (seit C++20)
constexpr std:: chrono :: year_month_weekday_last &
operator - = ( const std:: chrono :: months & dm ) const noexcept ;
(4) (seit C++20)

Modifiziert den Zeitpunkt, den * this repräsentiert, um die Dauer dy oder dm .

1) Entspricht * this = * this + dy ; .
2) Entspricht * this = * this + dm ; .
3) Entspricht * this = * this - dy ; .
4) Entspricht * this = * this - dm ; .

Für Zeitdauern, die sowohl in std::chrono::years als auch in std::chrono::months konvertierbar sind, werden die years Überladungen (1,3) bevorzugt, falls der Aufruf andernfalls mehrdeutig wäre.

Beispiel

#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';
}

Ausgabe:

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

Siehe auch

addiert oder subtrahiert ein year_month_weekday_last und eine Anzahl von Jahren oder Monaten
(Funktion)