std::chrono::duration<Rep,Period>::operator+=, -=, *=, /=, %=
Материал из cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (1) | ||
duration& operator+=(const duration& d); |
(до C++17) | |
constexpr duration& operator+=(const duration& d); |
(начиная с C++17) | |
| (2) | ||
duration& operator-=(const duration& d); |
(до C++17) | |
constexpr duration& operator-=(const duration& d); |
(начиная с C++17) | |
| (3) | ||
duration& operator*=(const rep& rhs); |
(до C++17) | |
constexpr duration& operator*=(const rep& rhs); |
(начиная с C++17) | |
| (4) | ||
duration& operator/=(const rep& rhs); |
(до C++17) | |
constexpr duration& operator/=(const rep& rhs); |
(начиная с C++17) | |
| (5) | ||
duration& operator%=(const rep& rhs); |
(до C++17) | |
constexpr duration& operator%=(const rep& rhs); |
(начиная с C++17) | |
| (6) | ||
duration& operator%=(const duration& rhs); |
(до C++17) | |
constexpr duration& operator%=(const duration& rhs); |
(начиная с C++17) | |
Выполняет составные присваивания между двумя длительностями с одинаковым периодом или между длительностью и значением счётчика тактов.
Если 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 | — | 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 минутам
Смотрите также
| увеличивает или уменьшает количество тактов (public функция-элемент) | |
| реализует арифметические операции с duration в качестве аргументов (шаблон функции) |