std::chrono:: is_clock
|
定义于头文件
<chrono>
|
||
|
template
<
class
T
>
struct is_clock ; |
(C++20 起) | |
若
T
满足
Clock
要求,则提供值为
true
的成员常量
value
。对于其他任何类型,
value
为
false
。
就本特性而言,实现判定某个类型不能满足
Clock
要求的程度是未指定的,但至少当类型
T
满足以下所有条件时才能被认定为
Clock
:
- 以下每个 限定标识符 均有效且表示一个类型:
-
-
T::rep -
T::period -
T::duration -
T::time_point
-
- 以下每个表达式在被视为 不求值操作数 时都是良构的:
-
-
T::is_steady -
T::now()
-
如果程序为
std::is_clock
或
std::is_clock_v
添加特化,其行为是未定义的。
目录 |
模板参数
| T | - | 待检查的类型 |
辅助变量模板
|
template
<
class
T
>
constexpr bool is_clock_v = is_clock < T > :: value ; |
(C++20 起) | |
继承自 std:: integral_constant
成员常量
|
value
[static]
|
若
T
满足
Clock
要求则为
true
,否则为
false
(公开静态成员常量) |
成员函数
|
operator bool
|
转换对象为
bool
类型,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
可能的实现
template<class> struct is_clock : std::false_type {}; template<class T> requires requires { typename T::rep; typename T::period; typename T::duration; typename T::time_point; T::is_steady; // 不检查类型 T::now(); // 不检查返回类型 } struct is_clock<T> : std::true_type {}; |
注释
若
T
在其他方面满足
Clock
要求,但
T::is_steady
的类型不是
const
bool
,或
T::now()
的返回类型不是
T
::
time_point
,则
is_clock_v<T>
的结果是未指定的。
示例
#include <chrono> #include <ratio> static_assert ( std::chrono::is_clock_v<std::chrono::utc_clock> and not std::chrono::is_clock_v<std::chrono::duration<int, std::exa>> ); int main() {}