std::chrono::ceil(std::chrono::time_point)
提供: cppreference.com
< cpp | chrono | time point
ヘッダ <chrono> で定義 | ||
template<class ToDuration, class Clock, class Duration> constexpr time_point<Clock, ToDuration> ceil(const time_point<Clock, Duration>& tp); | (C++17以上) | |
tp
より大きいまたは等しい、 ToDuration
で表現可能な最小の time point を返します。
この関数は、 ToDuration
が std::chrono::duration のインスタンスでなければ、オーバーロード解決に参加しません。
目次 |
[編集]引数
tp | - | 変換する time point |
[編集]戻り値
ToDuration
型の duration を使用する次の time point に切り上げた d
。
[編集]実装例
template<class T>struct is_duration :std::false_type{};template<class Rep, class Period>struct is_duration<std::chrono::duration<Rep, Period>>:std::true_type{}; template<class To, class Clock, class FromDuration, class=std::enable_if_t<is_duration<To>{}>>constexprstd::chrono::time_point<Clock, To> ceil(conststd::chrono::time_point<Clock, FromDuration>& tp){returnstd::chrono::time_point<Clock, To>{ std::chrono::ceil<To>(tp.time_since_epoch())};} |
[編集]例
Run this code
#include <iostream>#include <chrono>#include <string> template<typename TimePoint>std::string to_string(const TimePoint& time_point){returnstd::to_string(time_point.time_since_epoch().count());} int main(){usingnamespace std::literals::chrono_literals;using Sec =std::chrono::seconds; std::cout<<"Time point\t""Cast\t""Floor\t""Round\t""Ceil\n";std::cout<<"(ms)\t\t""(s)\t""(s)\t""(s)\t""(s)\n";for(constauto value_ms:{5432ms, 5678ms}){std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> time_point_ms(value_ms); std::cout<< to_string(time_point_ms)<<"\t\t"<< to_string(std::chrono::time_point_cast<Sec>(time_point_ms))<<"\t"<< to_string(std::chrono::floor<Sec>(time_point_ms))<<"\t"<< to_string(std::chrono::round<Sec>(time_point_ms))<<"\t"<< to_string(std::chrono::ceil<Sec>(time_point_ms))<<"\n";}}
出力:
Time point Cast Floor Round Ceil (ms) (s) (s) (s) (s) 5432 5 5 5 6 5678 5 5 6 6
[編集]関連項目
time point を同じ時計の異なる時間単位の time point に変換します (関数テンプレート) | |
time_point を別の time_point に切り捨て変換します (関数テンプレート) | |
time_point を別の time_point の最も近い値に変換します (関数テンプレート) | |
(C++17) | 時間を別の時間に切り上げ変換します (関数テンプレート) |
(C++11)(C++11) | 指定された値より小さくない最も近い整数を返します (関数) |