Namespaces
Variants

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

From cppreference.net
constexpr std:: chrono :: year & operator ++ ( ) noexcept ;
(1) (seit C++20)
constexpr std:: chrono :: year operator ++ ( int ) noexcept ;
(2) (seit C++20)
constexpr std:: chrono :: year & operator -- ( ) noexcept ;
(3) (seit C++20)
constexpr std:: chrono :: year operator -- ( int ) noexcept ;
(4) (seit C++20)

Addiert oder subtrahiert 1 vom Jahreswert.

1,2) Führt * this + = std:: chrono :: years { 1 } ; aus.
3,4) Führt * this - = std:: chrono :: years { 1 } ; aus.

Inhaltsverzeichnis

Parameter

(keine)

Rückgabewert

1,3) Ein Verweis auf dieses year nach der Modifikation.
2,4) Eine Kopie des year vor der Modifikation.

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()
{
    std::cout << std::boolalpha;
    std::chrono::year y{2020};
    std::cout << (++y == std::chrono::year(2021)) << ' ';
    std::cout << (--y == std::chrono::year(2020)) << '\n';
    using namespace std::literals::chrono_literals;
    y = 32767y;
    y++; //← unspecified, see ↑ Notes ↑
    std::cout << static_cast<int>(y) << '\n';
}

Mögliche Ausgabe:

true true
-32768

Siehe auch

addiert oder subtrahiert eine Anzahl von Jahren von einem year
(öffentliche Elementfunktion)
führt arithmetische Operationen auf year s aus
(Funktion)