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

履歴 編集

function template
<chrono>

std::chrono::round(C++17)

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())};

備考

  • treat_as_floating_point<typename ToDuration::rep>::value == trueである場合、この関数はオーバーロード解決の候補から外れる

#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 正の無限大方向への丸め

参照