std::chrono::duration<Rep,Period>::operator+=, -=, *=, /=, %=
来自 zh.cppreference.net
duration& operator+=( const duration& d );
|
(1) | (自C++11起) (自C++17起为constexpr) |
duration& operator-=( const duration& d );
|
(2) | (自C++11起) (自C++17起为constexpr) |
duration& operator*=( const rep& rhs );
|
(3) | (自C++11起) (自C++17起为constexpr) |
duration& operator/=( const rep& rhs );
|
(4) | (自C++11起) (自C++17起为constexpr) |
duration& operator%=( const rep& rhs );
|
(5) | (自C++11起) (自C++17起为constexpr) |
duration& operator%=( const duration& rhs );
|
(6) | (自C++11起) (自C++17起为constexpr) |
在两个具有相同周期的时长之间或在一个时长与一个计数值之间执行复合赋值。
如果 rep_ 是此时长对象中保存计数的成员变量,
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 | - | 操作符右侧的时长 |
| rhs | - | 操作符右侧的滴答数 |
返回值
修改后对此持续时间的引用。
示例
运行此代码
#include <chrono>
#include <iostream>
int main()
{
std::chrono::minutes m(11);
m *= 2;
m += std::chrono::hours(10); // hours implicitly convert to minutes
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
参见
|
递增或递减滴答计数
(公开成员函数) |
|
|
实现以时长为参数的算术运算
(函数模板) |