Namespaces
Variants

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

From cppreference.net
(1)
constexpr duration operator + ( ) const ;
(C++17まで)
constexpr std:: common_type_t < duration > operator + ( ) const ;
(C++17から)
(2)
constexpr duration operator - ( ) const ;
(C++17まで)
constexpr std:: common_type_t < duration > operator - ( ) const ;
(C++17から)

期間に対する単項プラスおよび単項マイナスを実装します。

rep_ が期間オブジェクト内のティック数を保持するメンバ変数であり、 D が戻り値の型である場合、

1) 次と同等 return D ( * this ) ; .
2) 次と同等 return D ( - rep_ ) ; .

目次

パラメータ

(なし)

戻り値

1) この期間オブジェクトのコピー。
2) この期間オブジェクトのコピーで、ティック数を負数にしたもの。

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

出力:

Negated -42s are 42s

関連項目

ティックカウントをインクリメントまたはデクリメントする
(public member function)
引数としてdurationを使用した算術演算を実装する
(function template)