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

从年份值中增加或减去 y. count ( ) 年。

1) 等价于 * this = * this + y ;
2) 等价于 * this = * this - y ;

目录

返回值

修改后对此 year 的引用。

注释

如果结果超出范围 [ - 32767 , 32767 ] ,实际存储的值是未指定的。

示例

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

输出:

true true

参见

递增或递减年份
(公开成员函数)
year 执行算术运算
(函数)