最終更新日時:
が更新

履歴 編集

function template
<chrono>

std::chrono::time_point_cast(C++11)

namespace std {
namespace chrono {
  template <class ToDuration, class Clock, class Duration>
  time_point<Clock, ToDuration>
    time_point_cast(const time_point<Clock, Duration>& t); // C++11

  template <class ToDuration, class Clock, class Duration>
  constexpr time_point<Clock, ToDuration>
    time_point_cast(const time_point<Clock, Duration>& t); // C++14
}}

概要

分解能の低いduration型を内部表現として持つtime_pointへの変換

戻り値

time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()));

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  typedef time_point<system_clock, milliseconds> MTimePoint;
  typedef time_point<system_clock, seconds>      STimePoint;

  MTimePoint mp(milliseconds(1100));

//STimePoint sp = mp; // error! 変換できない
  STimePoint sp = time_point_cast<seconds>(mp); // OK

  std::cout << sp.time_since_epoch().count() << std::endl;
}

出力

1

バージョン

言語

  • C++11

処理系

参照