std::chrono:: treat_as_floating_point
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더에 정의됨
<chrono>
|
||
|
template
<
class
Rep
>
struct treat_as_floating_point : std:: is_floating_point < Rep > { } ; |
(C++11부터) | |
std::chrono::treat_as_floating_point
trait은 duration이 다른 tick period를 가진 duration으로 변환될 수 있는지 여부를 결정하는 데 도움을 줍니다.
두 지속 시간 간의 암시적 변환은 일반적으로 지속 시간의 틱 주기에 따라 달라집니다. 그러나 std :: chrono :: treat_as_floating_point < Rep > :: value 가 true 인 경우 틱 주기와 관계없이 암시적 변환이 발생할 수 있습니다.
목차 |
헬퍼 변수 템플릿
|
template
<
class
Rep
>
constexpr bool treat_as_floating_point_v = treat_as_floating_point < Rep > :: value ; |
(C++17부터) | |
특수화
std::chrono::treat_as_floating_point
는 프로그램 정의 타입에 대해 특수화될 수 있습니다.
예제
#include <chrono> #include <iostream> #include <thread> void timed_piece_of_code() { std::chrono::milliseconds simulated_work(2); std::this_thread::sleep_for(simulated_work); } int main() { auto start = std::chrono::high_resolution_clock::now(); std::cout << "Running some timed piece of code...\n"; timed_piece_of_code(); auto stop = std::chrono::high_resolution_clock::now(); // 부동 소수점 밀리초 타입 using FpMilliseconds = std::chrono::duration<float, std::chrono::milliseconds::period>; static_assert(std::chrono::treat_as_floating_point<FpMilliseconds::rep>::value, "Rep required to be floating point"); // 여기서는 암시적 변환이 허용되지 않습니다 auto i_ms = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start); // 여기서는 암시적 변환이 허용됩니다 auto f_ms = FpMilliseconds(stop - start); std::cout << "Timing stats:\n"; std::cout << " Time in milliseconds, using default rep: " << i_ms.count() << '\n'; std::cout << " Time in milliseconds, using floating point rep: " << f_ms.count() << '\n'; }
가능한 출력:
Running some timed piece of code... Timing stats: Time in milliseconds, using default rep: 2 Time in milliseconds, using floating point rep: 2.57307
참고 항목
웹페이지의 텍스트를 한국어로 번역합니다: HTML 태그나 속성은 번역하지 마십시오. 원래 서식을 유지하십시오.
,
,