std::chrono::duration<Rep,Period>::operator+=, -=, *=, /=, %=
来自cppreference.com
| (1) | ||
| |
(C++11 起) (C++17 起为 constexpr) |
|
| (2) | ||
| |
(C++11 起) (C++17 起为 constexpr) |
|
| (3) | ||
| |
(C++11 起) (C++17 起为 constexpr) |
|
| (4) | ||
| |
(C++11 起) (C++17 起为 constexpr) |
|
| (5) | ||
| |
(C++11 起) (C++17 起为 constexpr) |
|
| (6) | ||
| |
(C++11 起) (C++17 起为 constexpr) |
|
在两个拥有同一周期的时长或时长和计次值之间进行复合赋值。
若 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() << " 分等于 "
<< std::chrono::duration_cast<std::chrono::hours>(m).count()
<< " 时又 ";
m %= std::chrono::hours(1);
std::cout << m.count() << " 分\n";
}
输出:
622 分等于 10 时又 22 分
参阅
| 自增或自减计次数 (公开成员函数) | |
| 实现以时长为实参的算术运算 (函数模板) |