std::chrono::year::operator++, std::chrono::year::operator--
來自 cppreference.com
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。
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++; //← unspecified, see ↑ Notes ↑ std::cout << static_cast<int>(y) << '\n'; }
可能的輸出
true true -32768
[編輯] 參閱
從 year 中增加或減去年數(public member function) | |
(C++20) |
對 year 進行算術運算(function) |