名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | chrono‎ | year
 
 
 
 
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