| (1) | ||
constexpr duration operator+() const; | (until C++17) | |
constexpr std::common_type_t<duration> operator+() const; | (since C++17) | |
| (2) | ||
constexpr duration operator-() const; | (until C++17) | |
constexpr std::common_type_t<duration> operator-() const; | (since C++17) |
Implements unary plus and unary minus for the durations.
If rep_ is a member variable holding the number of ticks in a duration object, and D is the return type,
return D(*this);
return D(-rep_);
(none).
#include <chrono>
#include <iostream>
int main()
{
std::chrono::seconds s1(10);
std::chrono::seconds s2 = -s1;
std::cout << "negated 10 seconds are " << s2.count() << " seconds\n";
}Output:
negated 10 seconds are -10 seconds
| increments or decrements the tick count (public member function) |
|
|
(C++11) | implements arithmetic operations with durations as arguments (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/chrono/duration/operator_arith