On this page
std::chrono::duration<Rep,Period>::operator+(unary), std::chrono::duration<Rep,Period>::operator-(unary)
(1) | ||
|
(until C++17) | |
|
(since C++17) | |
(2) | ||
|
(until C++17) | |
|
(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,
1) Equivalent to
return D(*this);
.
2) Equivalent to
return D(-rep_);
.
Parameters
(none)
Return value
1) A copy of this duration object.
2) A copy of this duration object, with the number of ticks negated.
Example
#include <chrono>
#include <iostream>
int main()
{
constexpr std::chrono::seconds s1(-052);
constexpr std::chrono::seconds s2 = -s1;
std::cout << "Negated " << s1 << " are " << s2 << '\n';
}
Output:
Negated -42s are 42s
See also
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