Namespaces
Variants
Views
Actions

std::chrono::duration<Rep,Period>::operator+(unary), std::chrono::duration<Rep,Period>::operator-(unary)

From cppreference.com
< cpp‎ | chrono‎ | duration
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Date and time utilities
(C++11)
(C++11)
Time of day
(C++20)



(C++20)(C++20)(C++20)(C++20)
Clocks
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Calendars
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time zones
(C++20)
(C++20)
(C++20)
(C++20)
C-style date and time
 
 
(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,

1) Equivalent to return D(*this);
2) Equivalent to return D(-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) [edit]
implements arithmetic operations with durations as arguments
(function template) [edit]