std::chrono::year::operator+=, std::chrono::year::operator-=
來自 cppreference.com
constexpr std::chrono::year& operator+=( const std::chrono::years& y ) noexcept; |
(1) | (C++20 起) |
constexpr std::chrono::year& operator-=( const std::chrono::years& y ) noexcept; |
(2) | (C++20 起) |
從年份值中增加或減去 y.count() 年。
1) 等價於 *this = *this + y;。
2) 等價於 *this = *this - y;。
目錄 |
[編輯] 返回值
修改後此 year
的引用。
[編輯] 注意
如果結果超出範圍 [
-32767,
32767]
,則實際儲存的值未指定。
[編輯] 示例
執行此程式碼
#include <chrono> #include <iostream> int main() { using namespace std::literals::chrono_literals; std::cout << std::boolalpha; std::chrono::year y{2020}; y += std::chrono::years(12); std::cout << (y == 2032y) << ' '; y -= std::chrono::years(33); std::cout << (y == 1999y) << '\n'; }
輸出
true true
[編輯] 參閱
遞增或遞減年份 (public member function) | |
(C++20) |
對 year 進行算術運算(function) |