Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |chrono‎ |duration
       
       
      Date and time library
       
      std::chrono::duration
       
      (1)
      constexpr duration operator+()const;
      (until C++17)
      constexprstd::common_type_t<duration> operator+()const;
      (since C++17)
      (2)
      constexpr duration operator-()const;
      (until C++17)
      constexprstd::common_type_t<duration> operator-()const;
      (since C++17)

      Implements unary plus and unary minus for the durations.

      Ifrep_ is a member variable holding the number of ticks in a duration object, andD is the return type,

      1) Equivalent toreturn D(*this);.
      2) Equivalent toreturn 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

      Run this code
      #include <chrono>#include <iostream> int main(){constexprstd::chrono::seconds s1(-052);constexprstd::chrono::seconds s2=-s1; std::cout<<"Negated "<< s1<<" are "<< s2<<'\n';}

      Output:

      Negated -42s are 42s

      [edit]See also

      increments or decrements the tick count
      (public member function)[edit]
      implements arithmetic operations with durations as arguments
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/duration/operator_arith&oldid=161871"

      [8]ページ先頭

      ©2009-2025 Movatter.jp