命名空间
变体
操作

std::chrono::duration<Rep,Period>::operator+=, -=, *=, /=, %=

来自 cppreference.cn
< cpp‎ | chrono‎ | duration
 
 
 
 
(1)
duration& operator+=( const duration& d );
(C++11 起)
(自 C++17 起为 constexpr)
(2)
duration& operator-=( const duration& d );
(C++11 起)
(自 C++17 起为 constexpr)
(3)
duration& operator*=( const rep& rhs );
(C++11 起)
(自 C++17 起为 constexpr)
(4)
duration& operator/=( const rep& rhs );
(C++11 起)
(自 C++17 起为 constexpr)
(5)
duration& operator%=( const rep& rhs );
(C++11 起)
(自 C++17 起为 constexpr)
(6)
duration& operator%=( const duration& rhs );
(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 - 运算符右侧的刻度数

[编辑] 返回值

修改后此 duration 的引用。

[编辑] 示例

#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

[编辑] 参阅

增加或减少刻度计数
(公共成员函数) [编辑]
实现以持续时间为参数的算术运算
(函数模板) [编辑]