- chrono[meta header]
- std::chrono[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
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
}}
- time_point[link /reference/chrono/time_point.md]
分解能の低いduration
型を内部表現として持つtime_point
へ変換する。
その際の丸めは、ゼロ方向への丸め (切り捨て、truncate) が行われる。
time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()));
- time_point[link /reference/chrono/time_point.md]
- duration_cast[link /reference/chrono/duration_cast.md]
- time_since_epoch[link /reference/chrono/time_point/time_since_epoch.md]
#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(1100));
//STimePoint sp = mp; // error! 変換できない
STimePoint sp = time_point_cast<seconds>(mp); // OK
std::cout << sp.time_since_epoch().count() << std::endl;
}
- time_point[link time_point.md]
- system_clock[link system_clock.md]
- time_point_cast[color ff0000]
- milliseconds[link milliseconds.md]
- seconds[link seconds.md]
- time_since_epoch()[link time_point/time_since_epoch.md]
- count()[link duration/count.md]
1
- C++11
- GCC, C++11 mode: 4.6.1
- Visual C++: 2012, 2013, 2015
名前 | 説明 |
---|---|
floor |
負の無限大方向への丸め |
ceil |
正の無限大方向への丸め |
round |
偶数方向への丸め |