最終更新日時(UTC):
が更新

履歴 編集

function template
<chrono>

std::chrono::operator-(C++11)

namespace std {
namespace chrono {
  template <class Rep1, class Period1, class Rep2, class Period2>
  constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
    operator-(const duration<Rep1, Period1>& lhs,
              const duration<Rep2, Period2>& rhs); // (1) C++11
}}

概要

durationの減算を行う

戻り値

  • (1)

using cd = common_type<decltype(lhs), decltype(rhs)>;
return cd(cd(lhs).count() - cd(rhs).count());

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  seconds s = seconds{3} - seconds{2};
  std::cout << s.count() << std::endl;

  milliseconds ms = seconds{3} - milliseconds{2};
  std::cout << ms.count() << std::endl;
}

出力

1
2998

バージョン

言語

  • C++11

処理系