• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <chrono>

    std::chrono::operator/

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

    概要

    durationの除算を行う

    • (1) : durationを任意の算術型で除算する
    • (2) : durationdurationで除算する

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

    戻り値

    • (1)

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

    • (2)

    using cd = typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type;
    return cd(lhs).count() / cd(rhs).count();
    

    #include <iostream>
    #include <chrono>
    
    using namespace std::chrono;
    
    int main()
    {
      // duration / rep
      {
        seconds s = seconds(8) / 2;
        std::cout << s.count() << std::endl;
    
        milliseconds ms = milliseconds(8) / 2;
        std::cout << ms.count() << std::endl;
      }
    
      // duration / duration
      {
        seconds::rep s = seconds(8) / seconds(2);
        std::cout << s << std::endl;
    
        milliseconds::rep ms = milliseconds(8) / milliseconds(2);
        std::cout << ms << std::endl;
      }
    }
    

    出力

    4
    4
    4
    4
    

    バージョン

    言語

    • C++11

    処理系

    • GCC: 4.6.1
    • Visual C++: 2012 , 2013 , 2015
      • 2013でサンプルコードをコンパイルしたところ、duration / durationでコンパイルエラーになった。

    参照