std::chrono::duration
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <chrono>
|
||
| template< class Rep, |
(C++11 起) | |
Class template std::chrono::duration represents a time interval.
It consists of a count of ticks of type Rep and a tick period, where the tick period is a compile-time rational constant representing the number of seconds from one tick to the next.
The only data stored in a duration is a tick count of type Rep. If Rep is floating point, then the duration can represent fractions of ticks. Period is included as part of the duration's type, and is only used when converting between different durations.
目錄 |
[编辑] 會員類型
| 會員類型
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
rep
|
Rep, an arithmetic type representing the number of ticks
|
period
|
Period, a std::ratio representing the tick period (i.e. the number of seconds per tick)
|
[编辑] 成員函數
| 構建新的持續時間 Original: constructs new duration The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成員函數) | |
| 分配的內容 Original: assigns the contents The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成員函數) | |
| 返回的計數蜱 Original: returns the count of ticks The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成員函數) | |
| [靜態的] </ SPAN></div></div>
|
returns the special duration value zero (公共靜態成員函數) |
| [靜態的] </ SPAN></div></div>
|
返回的時間值最小 Original: returns the special duration value min The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共靜態成員函數) |
| [靜態的] </ SPAN></div></div>
|
返回特殊的時間價值最大 Original: returns the special duration value max The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共靜態成員函數) |
| 實現一元+和一元 - Original: implements unary + and unary - The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成員函數) | |
| 遞增或遞減滴答計數 Original: increments or decrements the tick count The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成員函數) | |
| 實現複合賦值之間的持續時間 Original: implements compound assignment between two durations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成員函數) | |
[编辑] Non-member types
| 類型
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
| std::chrono::nanoseconds | duration type with Period std::nano |
| std::chrono::microseconds | duration type with Period std::micro |
| std::chrono::milliseconds | duration type with Period std::milli |
| std::chrono::seconds | duration type with Period std::ratio<1> |
| std::chrono::minutes | duration type with Period std::ratio<60> |
| std::chrono::hours | duration type with Period std::ratio<3600> |
[编辑] 非成員函數
| 專業的std::common_type特徵 Original: specializes the std::common_type trait The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (類模板專業化) | |
| 實現了算術運算的時間作為參數 Original: implements arithmetic operations with durations as arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函數模板) | |
| 比較兩個持續時間 Original: compares two durations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函數模板) | |
| 一個持續時間轉換到另一個,具有不同的周期的時間間隔 Original: converts a duration to another, with a different tick interval The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函數模板) | |
[编辑] Helper類
| indicates that a duration is convertible to duration with different tick period (類模板) | |
| constructs zero, min, and max values of a tick count of given type (類模板) | |
[编辑] 為例
This example shows how to define several custom duration types and convert between types:
#include <iostream> #include <chrono> int main() { typedef std::chrono::duration<int, std::ratio<1, 100000000>> shakes; typedef std::chrono::duration<int, std::centi> jiffies; typedef std::chrono::duration<float, std::ratio<12096,10000>> microfortnights; typedef std::chrono::duration<float, std::ratio<3155,1000>> nanocenturies; std::chrono::seconds sec(1); std::cout << "1 second is:\n"; std::cout << std::chrono::duration_cast<shakes>(sec).count() << " shakes\n"; std::cout << std::chrono::duration_cast<jiffies>(sec).count() << " jiffies\n"; std::cout << std::chrono::duration_cast<microfortnights>(sec).count() << " microfortnights\n"; std::cout << std::chrono::duration_cast<nanocenturies>(sec).count() << " nanocenturies\n"; }
Output:
1 second is: 100000000 shakes 100 jiffies 0.82672 microfortnights 0.316957 nanocenturies