在线文档教程
C++
应用 | Utilities

std::chrono::duration::operators (%=)

时间::持续时间::操作员+=,-=,%2A%=

(1)
duration& operator+=(const duration& d(until C++17)
constexpr duration& operator+=(const duration& d(since C++17)
(2)
duration& operator-=(const duration& d(until C++17)
constexpr duration& operator-=(const duration& d(since C++17)
(3)
duration& operator*=(const rep& rhs(until C++17)
constexpr duration& operator*=(const rep& rhs(since C++17)
(4)
duration& operator/=(const rep& rhs(until C++17)
constexpr duration& operator/=(const rep& rhs(since C++17)
(5)
duration& operator%=(const rep& rhs(until C++17)
constexpr duration& operator%=(const rep& rhs(since C++17)
(6)
duration& operator%=(const duration& rhs(until C++17)
constexpr duration& operator%=(const duration& rhs(since C++17)

在具有相同期间的两个工期之间或在工期与滴答计数值之间执行复合赋值。

如果rep_成员变量保存此持续时间对象中的滴答数,

1%29相当于rep_ += d.count( return *this;

2%29相当于rep_ -= d.count( return *this;

3%29相当于rep_ *= rhs; return *this;

4%29相当于rep_ /= rhs; return *this;

5%29相当于rep_ %= rhs; return *this;

6%29相当于rep_ %= d.count( return *this;

参数

d-duration on the right-hand side of the operator
rhs-number of ticks on the right-hand side of the operator

返回值

修改后对此持续时间的引用。

二次

#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

二次

另见

operator++operator++(int)operator--operator--(int)increments or decrements the tick count (public member function)
operator+operator-operator*operator/operator%implements arithmetic operations with durations as arguments (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/rono/time/Operator[医]算术3