Namespaces
Variants

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

From cppreference.net
constexpr std:: chrono :: year & operator + = ( const std:: chrono :: years & y ) noexcept ;
(1) (seit C++20)
constexpr std:: chrono :: year & operator - = ( const std:: chrono :: years & y ) noexcept ;
(2) (seit C++20)

Fügt y. count ( ) Jahre zum Jahrwert hinzu oder subtrahiert sie davon.

1) Entspricht * this = * this + y ; .
2) Entspricht * this = * this - y ; .

Inhaltsverzeichnis

Rückgabewert

Ein Verweis auf dieses year nach der Änderung.

Hinweise

Wenn das Ergebnis außerhalb des Bereichs [ - 32767 , 32767 ] liegen würde, ist der tatsächlich gespeicherte Wert nicht spezifiziert.

Beispiel

#include <chrono>
#include <iostream>
int main()
{
    using namespace std::literals::chrono_literals;
    std::cout << std::boolalpha;
    std::chrono::year y{2020};
    y += std::chrono::years(12);
    std::cout << (y == 2032y) << ' ';
    y -= std::chrono::years(33);
    std::cout << (y == 1999y) << '\n';
}

Ausgabe:

true true

Siehe auch

erhöht oder verringert das Jahr
(öffentliche Elementfunktion)
führt arithmetische Operationen auf year s aus
(Funktion)