std::chrono::duration::duration
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
constexpr duration() = default; |
(1) | |
duration(const duration&) = default; |
(2) | |
template <class Rep2> constexpr explicit duration(const Rep2& r); |
(3) | |
template <class Rep2, class Period2> constexpr duration(const duration<Rep2, Period2>& d); |
(4) | |
,构造一个新的
duration
从几个可选的数据源之一原文:
Constructs a new
duration
from one of several optional data sources.1)
默认的构造函数,默认
原文:
The default constructor is defaulted.
2)
默认的拷贝构造函数(的刻度数位复制).
原文:
The copy constructor is defaulted (makes a bitwise copy of the tick count).
3)
r
蜱构造一个持续时间。请注意,此构造仅参与重载解析,如果Rep2
(参数类型)是隐式转换为rep
(这个时间的滴答)和原文:
Constructs a duration with
r
ticks. Note that this constructor only participates in overload resolution if Rep2
(the argument type) is implicitly convertible to rep
(the type of this duration's ticks) and- std::chrono::treat_as_floating_point<rep>::value是真实的原文:std::chrono::treat_as_floating_point<rep>::value is true, or
- std::chrono::treat_as_floating_point<Rep2>::value是假的原文:std::chrono::treat_as_floating_point<Rep2>::value is false.
-
@ @(即,持续时间与一个整数滴答计数不能构造从一个浮点值,但是可以构造一个浮点滴答计数的持续时间,从一个整数值)
原文:
@@(that is, a duration with an integer tick count cannot be constructed from a floating-point value, but a duration with a floating-point tick count can be constructed from an integer value)
4)
构造一个持续时间
d
转换到一个适当的时间和刻度数,如果由std::chrono::duration_cast<duration>(d).count()。为了防止在转换过程中被截断,该构造函数只参加在重载决议原文:
Constructs a duration by converting
d
to an appropriate period and tick count, as if by std::chrono::duration_cast<duration>(d).count(). In order to prevent truncation during conversion, this constructor only participates in overload resolution if:- std::chrono::treat_as_floating_point<rep>::value == true
@ @或两个:
- std::ratio_divide<Period2, period>::den == 1, and
- std::chrono::treat_as_floating_point<Rep2>::value == false.
@ @(也就是说,或者持续时间使用浮点蜱,或
Period2
是按期间整除的)原文:
@@ (that is, either the duration uses floating-point ticks, or
Period2
is exactly divisible by period)[编辑] 参数
r | - | 一个时钟周期数
|
d | - | 复制的持续时间
|
[编辑] 示例
代码显示了几个例子(有效和无效)如何构建持续时间“
原文:
The following code shows several examples (both valid and invalid) of how to construct durations:
#include <chrono> int main() { std::chrono::hours h(1); // one hour std::chrono::milliseconds ms{3}; // 3 milliseconds std::chrono::duration<int, std::kilo> ks(3); // 3000 seconds // error: treat_as_floating_point<int>::value == false, // This duration allows whole tick counts only // std::chrono::duration<int, std::kilo> d3(3.5); // 30Hz clock using fractional ticks std::chrono::duration<double, std::ratio<1, 30>> hz30(3.5); // 3000 microseconds constructed from 3 milliseconds std::chrono::microseconds us = ms; // error: 1/1000000 is not divisible by 1/1000 // std::chrono::milliseconds ms2 = us }
[编辑] 另请参阅
分配的内容 (公共成员函数) |