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) (desde C++20)
constexpr std:: chrono :: year & operator - = ( const std:: chrono :: years & y ) noexcept ;
(2) (desde C++20)

Agrega o resta y. count ( ) años del valor del año.

1) Equivalente a * this = * this + y ; .
2) Equivalente a * this = * this - y ; .

Contenidos

Valor de retorno

Una referencia a este year después de la modificación.

Notas

Si el resultado estuviera fuera del rango [ - 32767 , 32767 ] , el valor almacenado real no está especificado.

Ejemplo

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

Salida:

true true

Véase también

incrementa o decrementa el año
(función miembro pública)
realiza operaciones aritméticas con year s
(función)