命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | chrono‎ | year
 
 
 
 
constexpr std::chrono::year operator+() noexcept;
(1) (since C++20)
constexpr std::chrono::year operator-() noexcept;
(2) (since 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