• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <chrono>

    std::chrono::round

    namespace std::chrono {
      template <class ToDuration, class Clock, class Duration>
      constexpr time_point<Clock, ToDuration>
        round(const time_point<Clock, Duration>& tp);
    }
    

    概要

    分解能が低いtime_pointに変換する際に、偶数方向への丸め (最近接偶数への丸め) を行う。

    戻り値

    return time_point<Clock, ToDuration>{round<ToDuration>(tp.time_since_epoch())};
    

    備考

    #include <iostream>
    #include <chrono>
    
    using namespace std::chrono;
    
    int main()
    {
      using MTimePoint = time_point<system_clock, milliseconds>;
      using STimePoint = time_point<system_clock, seconds>;
    
      MTimePoint mp{milliseconds(1500)};
      STimePoint sp = round<seconds>(mp);
    
      std::cout << sp.time_since_epoch().count() << std::endl;
    }
    

    出力

    2
    

    バージョン

    言語

    • C++17

    処理系

    関連項目

    名前 説明
    time_point_cast ゼロ方向への丸め
    floor 負の無限大方向への丸め
    ceil 正の無限大方向への丸め

    参照