std::chrono:: clock_time_conversion
|
定义于头文件
<chrono>
|
||
|
template
<
class
Dest,
class
Source
>
struct clock_time_conversion { } ; |
(C++20 起) | |
std::chrono::clock_time_conversion
是一个特性类,用于指定如何将
std::chrono::time_point
从
Source
时钟转换到
Dest
时钟。它通过提供一个常量可调用的
operator()
来实现,该操作符接受类型为
std::
chrono
::
time_point
<
Source, Duration
>
的参数,并返回一个表示相同时间点的
std::
chrono
::
time_point
<
Dest, OtherDuration
>
。返回时间点的时长是根据源时长计算得出的,具体计算方式因特化实现而异。
clock_time_conversion
通常仅通过
std::chrono::clock_cast
间接使用。
当至少一个模板参数为用户定义的时钟类型时,程序可以特化
clock_time_conversion
。
主模板是一个空结构体。标准定义了以下特化版本:
|
template
<
class
Clock
>
struct clock_time_conversion < Clock, Clock > ; |
(1) | (自 C++20 起) |
|
template
<>
struct clock_time_conversion < std:: chrono :: system_clock , std:: chrono :: system_clock > ; |
(2) | (自 C++20 起) |
|
template
<>
struct clock_time_conversion < std:: chrono :: utc_clock , std:: chrono :: utc_clock > ; |
(3) | (自 C++20 起) |
|
template
<>
struct clock_time_conversion < std:: chrono :: system_clock , std:: chrono :: utc_clock > ; |
(4) | (自 C++20 起) |
|
template
<>
struct clock_time_conversion < std:: chrono :: utc_clock , std:: chrono :: system_clock > ; |
(5) | (自 C++20 起) |
|
template
<
class
Clock
>
struct clock_time_conversion < Clock, std:: chrono :: system_clock > ; |
(6) | (自 C++20 起) |
|
template
<
class
Clock
>
struct clock_time_conversion < std:: chrono :: system_clock , Clock > ; |
(7) | (自 C++20 起) |
|
template
<
class
Clock
>
struct clock_time_conversion < Clock, std:: chrono :: utc_clock > ; |
(8) | (自 C++20 起) |
|
template
<
class
Clock
>
struct clock_time_conversion < std:: chrono :: utc_clock , Clock > ; |
(9) | (自 C++20 起) |
operator()
返回参数的副本。
operator()
分别调用
std::chrono::utc_clock::to_sys
和
std::chrono::utc_clock::from_sys
。
Clock
支持
from_sys
和
to_sys
时):
operator()
分别调用
Clock
::
to_sys
和
Clock
::
from_sys
。
Clock
支持
from_utc
和
to_utc
时):
operator()
分别调用
Clock
::
to_utc
和
Clock
::
from_utc
。
目录 |
成员函数
每个特化都有一个隐式声明的默认构造函数、复制构造函数、移动构造函数、复制赋值运算符、移动赋值运算符和析构函数。
std::chrono::clock_time_conversion:: operator()
|
template
<
class
Duration
>
std::
chrono
::
time_point
<
Clock, Duration
>
|
(1) | (特化的成员函数 (1) ) |
|
template
<
class
Duration
>
std::
chrono
::
sys_time
<
Duration
>
|
(2) | (特化成员 (2) ) |
|
template
<
class
Duration
>
std::
chrono
::
utc_time
<
Duration
>
|
(3) | (特化成员 (3) ) |
|
template
<
class
Duration
>
std::
chrono
::
sys_time
<
Duration
>
|
(4) | (特化成员 (4) ) |
|
template
<
class
Duration
>
std::
chrono
::
utc_time
<
Duration
>
|
(5) | (特化成员 (5) ) |
|
template
<
class
Duration
>
auto
operator
(
)
(
const
std::
chrono
::
sys_time
<
Duration
>
&
t
)
const
|
(6) | (特化成员 (6) ) |
|
template
<
class
Duration
>
auto
operator
(
)
(
const
std::
chrono
::
time_point
<
SourceClock, Duration
>
&
t
)
const
|
(7) | (特化成员 (7) ) |
|
template
<
class
Duration
>
auto
operator
(
)
(
const
std::
chrono
::
utc_time
<
Duration
>
&
t
)
const
|
(8) | (特化成员 (8) ) |
|
template
<
class
Duration
>
auto
operator
(
)
(
const
std::
chrono
::
time_point
<
Clock, Duration
>
&
t
)
const
|
(9) | (特化成员 (9) ) |
将参数 std::chrono::time_point 转换为目标时钟。
t
。
Duration
为
std::chrono::duration
的某个有效特化),则程序非良构。
Duration
为
std::chrono::duration
的某个有效特化),则程序非良构。
Duration
为
std::chrono::duration
的某个有效特化),则程序非良构。
Duration
是
std::chrono::duration
的某个有效特化),则程序非良构。
参数
| t | - | 要转换的时间点 |
返回值
如上所述的转换结果:
另请参阅
|
(C++20)
|
将一个时钟的时间点转换为另一个时钟的时间点
(函数模板) |