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

履歴 編集

function template
<chrono>

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

namespace std {
namespace chrono {
  // duration * N = duration
  template <class Rep1, class Period, class Rep2>
  duration<typename common_type<Rep1, Rep2>::type, Period>
    constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s); // (1)

  // N * duration = duration
  template <class Rep1, class Rep2, class Period>
  duration<typename common_type<Rep1, Rep2>::type, Period>
    constexpr operator*(const Rep1& s, const duration<Rep2, Period>& d); // (2)
}}

概要

durationの乗算を行う

テンプレートパラメータ制約

戻り値

using cd = duration<typename common_type<Rep1, Rep2>::type, Period>;
return cd(cd(d).count() * s);

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  // duration * rep
  {
    seconds s = seconds(3) * 2;
    std::cout << s.count() << std::endl;

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

  // rep * duration
  {
    seconds s = 2 * seconds(3);
    std::cout << s.count() << std::endl;

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

出力

6
6
6
6

バージョン

言語

  • C++11

処理系

参照