std::chrono::year::operator+, std::chrono::year::operator-
来自cppreference.com
constexpr std::chrono::year operator+() noexcept; |
(1) | (C++20 起) |
constexpr std::chrono::year operator-() noexcept; |
(2) | (C++20 起) |
应用一元运算符到年份值。
1) 返回 *this 的副本。
2) 返回年份值为 *this 的年份值相反数的
year
。返回值
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 << "年份 " << (int)y << " 取负值为 " << (int)ny << '\n'; }
输出:
年份 2020 取负值为 -2020