std::chrono::duration<Rep,Period>::operator+=, -=, *=, /=, %=
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    | (1) | ||
|   duration& operator+=(const duration& d);  | 
(C++17 前) | |
|   constexpr duration& operator+=(const duration& d);  | 
(C++17 起) | |
| (2) | ||
|   duration& operator-=(const duration& d);  | 
(C++17 前) | |
|   constexpr duration& operator-=(const duration& d);  | 
(C++17 起) | |
| (3) | ||
|   duration& operator*=(const rep& rhs);  | 
(C++17 前) | |
|   constexpr duration& operator*=(const rep& rhs);  | 
(C++17 起) | |
| (4) | ||
|   duration& operator/=(const rep& rhs);  | 
(C++17 前) | |
|   constexpr duration& operator/=(const rep& rhs);  | 
(C++17 起) | |
| (5) | ||
|   duration& operator%=(const rep& rhs);  | 
(C++17 前) | |
|   constexpr duration& operator%=(const rep& rhs);  | 
(C++17 起) | |
| (6) | ||
|   duration& operator%=(const duration& rhs);  | 
(C++17 前) | |
|   constexpr duration& operator%=(const duration& rhs);  | 
(C++17 起) | |
在二个拥有同一周期的时长或时长和计次值之间进行复合赋值。
若 rep_ 是此 duration 对象中保有计次数的成员变量,则
1) 等价于 rep_ += d.count(); return *this;
2) 等价于 rep_ -= d.count(); return *this;
3) 等价于 rep_ *= rhs; return *this;
4) 等价于 rep_ /= rhs; return *this;
5) 等价于 rep_ %= rhs; return *this;
6) 等价于 rep_ %= d.count(); return *this;
参数
| d | - | 运算符右侧的 duration | 
| rhs | - | 运算符右侧的计次数 | 
返回值
到修改后的此 duration 的引用
示例
运行此代码
#include <chrono> #include <iostream> int main() { std::chrono::minutes m(11); m *= 2; m += std::chrono::hours(10); // 小时可隐式转换成分 std::cout << m.count() << " minutes equals " << std::chrono::duration_cast<std::chrono::hours>(m).count() << " hours and "; m %= std::chrono::hours(1); std::cout << m.count() << " minutes\n"; }
输出:
622 minutes equals 10 hours and 22 minutes
参阅
|   递增或递减滴答计数  (公开成员函数)  | |
|   实现以时长为实参的算术运算  (函数模板)  |