duration& operator+=(const duration& d); | (1) | |
duration& operator-=(const duration& d); | (2) | |
duration& operator*=(const rep& rhs); | (3) | |
duration& operator/=(const rep& rhs); | (4) | |
duration& operator%=(const rep& rhs); | (5) | |
duration& operator%=(const duration& rhs); | (6) |
Performs compound assignments between two durations with the same period or between a duration and a tick count value.
If rep_
is the member variable holding the number of ticks in this duration object,
rep_ += d.count(); return *this;
rep_ -= d.count(); return *this;
rep_ *= rhs; return *this;
rep_ /= rhs; return *this;
rep_ %= rhs; return *this;
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 |
A reference to this duration after modification.
#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"; }
Output:
622 minutes equals 10 hours and 22 minutes
increments or decrements the tick count (public member function) |
|
implements arithmetic operations with durations as arguments (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/chrono/duration/operator_arith3