Namespaces
Variants

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

From cppreference.net
헤더 파일에 정의됨 <chrono>
template < class ToDuration, class Clock, class Duration >

constexpr std:: chrono :: time_point < Clock, ToDuration >

ceil ( const std:: chrono :: time_point < Clock, Duration > & tp ) ;
(C++17부터)

tp 보다 크거나 같은 시간 포인트 중 ToDuration 에서 표현 가능한 가장 작은 시간 포인트 t 를 반환합니다.

이 함수는 다음 조건을 만족하지 않는 한 오버로드 해결에 참여하지 않습니다: ToDuration std::chrono::duration 의 특수화(specialization)인 경우.

목차

매개변수

tp - 반올림할 시간 포인트

반환값

tp ToDuration 유형의 지속 시간을 사용하여 다음 시간 포인트로 올림 처리합니다.

가능한 구현

namespace detail
{
    template<class> inline constexpr bool is_duration_v = false;
    template<class Rep, class Period> inline constexpr bool is_duration_v<
        std::chrono::duration<Rep, Period>> = true;
}
template<class To, class Clock, class FromDuration,
         class = std::enable_if_t<detail::is_duration_v<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 <chrono>
#include <iostream>
#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

참고 항목

동일한 클록에서 다른 duration을 가진 시간 포인트로 변환
(함수 템플릿)
시간 포인트를 다른 시간 포인트로 변환하며, 내림 처리
(함수 템플릿)
시간 포인트를 다른 시간 포인트로 변환하며, 가장 가까운 값으로 반올림 (동점시 짝수로)
(함수 템플릿)
duration을 다른 duration으로 변환하며, 올림 처리
(함수 템플릿)
(C++11) (C++11)
주어진 값보다 작지 않은 가장 가까운 정수
(함수)