Namespaces
Variants

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

From cppreference.net
(1)
constexpr duration operator + ( ) const ;
(bis C++17)
constexpr std:: common_type_t < duration > operator + ( ) const ;
(seit C++17)
(2)
constexpr duration operator - ( ) const ;
(bis C++17)
constexpr std:: common_type_t < duration > operator - ( ) const ;
(seit C++17)

Implementiert unäres Plus und unäres Minus für die Dauern.

Wenn rep_ eine Membervariable ist, die die Anzahl der Ticks in einem Duration-Objekt speichert, und D der Rückgabetyp ist,

1) Entspricht return D ( * this ) ; .
2) Entspricht return D ( - rep_ ) ; .

Inhaltsverzeichnis

Parameter

(keine)

Rückgabewert

1) Eine Kopie dieses Dauer-Objekts.
2) Eine Kopie dieses Dauer-Objekts, mit der Anzahl der Ticks negiert.

Beispiel

#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';
}

Ausgabe:

Negated -42s are 42s

Siehe auch

erhöht oder verringert die Tickanzahl
(öffentliche Elementfunktion)
implementiert arithmetische Operationen mit Dauern als Argumente
(Funktions-Template)