名前空間
変種
操作

std::chrono::ceil(std::chrono::time_point)

提供: cppreference.com
< cpp‎ | chrono‎ | time point
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
日付と時間のユーティリティ
(C++11)
(C++11)
時刻
(C++20)



(C++20)(C++20)(C++20)(C++20)
時計
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
カレンダー
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
タイムゾーン
(C++20)
(C++20)
(C++20)
(C++20)
C スタイルの日付と時間
 
 
ヘッダ <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 を返します。

この関数は、 ToDurationstd::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>{}>>
constexpr std::chrono::time_point<Clock, To>
    ceil(const std::chrono::time_point<Clock, FromDuration>& tp)
{
    return std::chrono::time_point<Clock, To>{
               std::chrono::ceil<To>(tp.time_since_epoch())};
}

[編集]

#include <iostream>
#include <chrono>
#include <string>
 
template <typename TimePoint>
std::string to_string(const TimePoint& time_point)
{
    return std::to_string(time_point.time_since_epoch().count());
}
 
int main()
{
    using namespace 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 (const auto 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 に変換します
(関数テンプレート) [edit]
time_point を別の time_point に切り捨て変換します
(関数テンプレート) [edit]
time_point を別の time_point の最も近い値に変換します
(関数テンプレート) [edit]
時間を別の時間に切り上げ変換します
(関数テンプレート) [edit]
(C++11)(C++11)
指定された値より小さくない最も近い整数を返します
(関数) [edit]