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) 返回一个
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