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

履歴 編集

function template
<chrono>

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

namespace std::chrono {
  template <class ToDuration, class Rep, class Period>
  constexpr ToDuration round(const duration<Rep, Period>& d);
}

概要

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

戻り値

dから最も近い偶数値を返す。

備考

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

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  milliseconds ms{1500};
  seconds s = round<seconds>(ms);

  std::cout << s.count() << std::endl;
}

出力

2

バージョン

言語

  • C++17

処理系

関連項目

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

参照