std::chrono::duration
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <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.
目录 |
[编辑] 会员类型
会员类型
|
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)
|
[编辑] 成员函数
构建新的持续时间 (公共成员函数) | |
分配的内容 (公共成员函数) | |
返回的计数蜱 (公共成员函数) | |
[静态的]</div></div>
|
returns the special duration value zero (公共静态成员函数) |
[静态的]</div></div>
|
返回的时间值最小 原文: returns the special duration value min (公共静态成员函数) |
[静态的]</div></div>
|
返回特殊的时间价值最大 原文: returns the special duration value max (公共静态成员函数) |
实现一元+和一元 - (公共成员函数) | |
递增或递减滴答计数 原文: increments or decrements the tick count (公共成员函数) | |
实现复合赋值之间的持续时间 原文: implements compound assignment between two durations (公共成员函数) |
[编辑] Non-member types
类型
|
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特征 原文: specializes the std::common_type trait (类模板特化) | |
实现了算术运算的时间作为参数 原文: implements arithmetic operations with durations as arguments (函数模板) | |
比较两个持续时间 (函数模板) | |
一个持续时间转换到另一个,具有不同的周期的时间间隔 原文: converts a duration to another, with a different tick interval (函数模板) |
[编辑] 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"; }
输出:
1 second is: 100000000 shakes 100 jiffies 0.82672 microfortnights 0.316957 nanocenturies