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 - ( ) noexcept ;
(2) (C++20 起)

对年份值应用一元运算符。

1) 返回 * this 的副本。
2) 返回一个 year 对象,其年份值为 * this 年份值的相反数。

返回值

1) * this
2) std:: chrono :: year ( - int ( * this ) )

示例

#include <chrono>
#include <iostream>
int main()
{
    constexpr std::chrono::year y{2020};
    constexpr auto ny = -y;
    std::cout << "The year " << (int)y << " negated is " << (int)ny << '\n';
}

输出:

The year 2020 negated is -2020