std::chrono::year::operator++, std::chrono::year::operator--
constexpr std::chrono::year& operator++() noexcept;
|
(1) | (C++20 起) |
constexpr std::chrono::year operator++( int ) noexcept;
|
(2) | (C++20 起) |
constexpr std::chrono::year& operator--() noexcept;
|
(3) | (C++20 起) |
constexpr std::chrono::year operator--( int ) noexcept;
|
(4) | (C++20 起) |
从年份值加或减 1。
1,2) 实施 *this += std::chrono::years{1};。
3,4) 实施 *this -= std::chrono::years{1};。
参数
(无)
返回值
1,3) 到修改后的此
year
的引用。2,4) 修改前所作的
year
的副本。注意
若结果会在范围 [
-32767,
32767]
外,则实际存储的值未指定。
示例
#include <chrono> #include <iostream> int main() { std::cout << std::boolalpha; std::chrono::year y{2020}; std::cout << (++y == std::chrono::year(2021)) << ' '; std::cout << (--y == std::chrono::year(2020)) << '\n'; using namespace std::literals::chrono_literals; y = 32767y; y++; //← 未指明, 参见 ↑ 注解 ↑ std::cout << static_cast<int>(y) << '\n'; }
可能的输出:
true true -32768
参阅
从 year 加上或减去年数(公开成员函数) |
|
(C++20)
|
进行 year 上的算术(函数) |