Namespaces
Variants

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

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

对年份值加1或减1。

1,2) 执行 * this + = std:: chrono :: years { 1 } ;
3,4) 执行 * this - = std:: chrono :: years { 1 } ;

目录

参数

(无)

返回值

1,3) 修改后此 year 的引用。
2,4) 修改前 year 的副本。

注释

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

示例

#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++; //← 未指定行为,请参阅↑注释↑
    std::cout << static_cast<int>(y) << '\n';
}

可能的输出:

true true
-32768

参见

year 对象进行年数的加法或减法运算
(公开成员函数)
year 对象执行算术运算
(函数)