std::chrono:: floor (std::chrono::duration)
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::duration
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<chrono>
|
||
|
template
<
class
ToDuration,
class
Rep,
class
Period
>
constexpr ToDuration floor ( const std:: chrono :: duration < Rep, Period > & d ) ; |
(C++17부터) | |
ToDuration
에서 표현 가능한 가장 긴 지속 시간
t
를 반환하며, 이는
d
보다 작거나 같습니다.
이 함수는 다음 조건을 만족하지 않는 한 오버로드 해결에 참여하지 않습니다:
ToDuration
가
std::chrono::duration
의 특수화(specialization)인 경우.
목차 |
매개변수
| d | - | 변환할 지속 시간 |
반환값
d
를
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 Rep, class Period, class = std::enable_if_t<detail::is_duration_v<To>>> constexpr To floor(const duration<Rep, Period>& d) { To t = std::chrono::duration_cast<To>(d); if (t > d) return t - To{1}; return t; } |
예제
이 코드 실행
#include <chrono> #include <iomanip> #include <iostream> int main() { using namespace std::chrono_literals; std::cout << "Duration\tFloor\tRound\tCeil\n"; for (using Sec = std::chrono::seconds; auto const d : {+4999ms, +5000ms, +5001ms, +5499ms, +5500ms, +5999ms, -4999ms, -5000ms, -5001ms, -5499ms, -5500ms, -5999ms}) std::cout << std::showpos << d << "\t\t" << std::chrono::floor<Sec>(d) << '\t' << std::chrono::round<Sec>(d) << '\t' << std::chrono::ceil <Sec>(d) << '\n'; }
출력:
Duration Floor Round Ceil +4999ms +4s +5s +5s +5000ms +5s +5s +5s +5001ms +5s +5s +6s +5499ms +5s +5s +6s +5500ms +5s +6s +6s +5999ms +5s +6s +6s -4999ms -5s -5s -4s -5000ms -5s -5s -5s -5001ms -6s -5s -5s -5499ms -6s -5s -5s -5500ms -6s -6s -5s -5999ms -6s -6s -5s
참고 항목
|
(C++11)
|
다른 틱 간격을 가진 duration으로 변환합니다
(함수 템플릿) |
|
(C++17)
|
duration을 다른 단위로 변환하며, 올림 처리합니다
(함수 템플릿) |
|
(C++17)
|
duration을 다른 단위로 변환하며, 가장 가까운 값으로 반올림합니다(동점 시 짝수로)
(함수 템플릿) |
|
(C++17)
|
time_point를 다른 단위로 변환하며, 내림 처리합니다
(함수 템플릿) |
|
(C++11)
(C++11)
|
주어진 값보다 크지 않은 가장 가까운 정수
(함수) |