std::chrono::duration::operator+(unary), std::chrono::duration::operator-(unary)

From cppreference.com
< cpp‎ | chrono‎ | duration
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
 
 
constexpr duration operator+() const;
(1)
constexpr duration operator-() const;
(2)

Implements unary plus and unary minus for the durations.

If rep_ is a member variable holding the number of ticks in a duration object,

1) Equivalent to return *this;
2) Equivalent to return duration(-rep_);

Contents

[edit] Parameters

(none)

[edit] Return value

1) a copy of this duration object
2) a copy of this duration object, with the number of ticks negated

[edit] Example

#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

[edit] See also

increments or decrements the tick count
(public member function)
implements arithmetic operations with durations as arguments
(function template)