std:: is_invocable, std:: is_invocable_r, std:: is_nothrow_invocable, std:: is_nothrow_invocable_r
|
定义于头文件
<type_traits>
|
||
|
template
<
class
Fn,
class
...
ArgTypes
>
struct is_invocable ; |
(1) | (C++17 起) |
|
template
<
class
R,
class
Fn,
class
...
ArgTypes
>
struct is_invocable_r ; |
(2) | (C++17 起) |
|
template
<
class
Fn,
class
...
ArgTypes
>
struct is_nothrow_invocable ; |
(3) | (C++17 起) |
|
template
<
class
R,
class
Fn,
class
...
ArgTypes
>
struct is_nothrow_invocable_r ; |
(4) | (C++17 起) |
如果
Fn, R
或参数包
ArgTypes
中的任何类型不是完整类型、(可能带有 cv 限定符的)
void
,或未知边界的数组,则行为未定义。
如果上述模板的实例化直接或间接依赖于不完整类型,且该实例化在该类型被假设完成时可能产生不同结果,则行为是未定义的。
如果程序对本页面描述的任何模板添加特化,则行为未定义。
目录 |
辅助变量模板
|
定义于头文件
<type_traits>
|
||
|
template
<
class
Fn,
class
...
ArgTypes
>
inline
constexpr
bool
is_invocable_v
=
|
(1) | (C++17 起) |
|
template
<
class
R,
class
Fn,
class
...
ArgTypes
>
inline
constexpr
bool
is_invocable_r_v
=
|
(2) | (C++17 起) |
|
template
<
class
Fn,
class
...
ArgTypes
>
inline
constexpr
bool
is_nothrow_invocable_v
=
|
(3) | (C++17 起) |
|
template
<
class
R,
class
Fn,
class
...
ArgTypes
>
inline
constexpr
bool
is_nothrow_invocable_r_v
=
|
(4) | (C++17 起) |
继承自 std:: integral_constant
成员常量
|
value
[static]
|
若(对于重载
(1)
)
INVOKE
(
std::
declval
<
Fn
>
(
)
,
std::
declval
<
ArgTypes
>
(
)
...
)
作为未求值操作数时合法则为
true
,否则为
false
(公开静态成员常量) |
成员函数
|
operator bool
|
转换对象为
bool
类型,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
注释
| 功能测试 宏 | 值 | 标准 | 功能 |
|---|---|---|---|
__cpp_lib_is_invocable
|
201703L
|
(C++17) |
std::is_invocable
,
std::invoke_result
|
示例
#include <type_traits> auto func2(char) -> int (*)() { return nullptr; } int main() { static_assert(std::is_invocable_v<int()>); static_assert(not std::is_invocable_v<int(), int>); static_assert(std::is_invocable_r_v<int, int()>); static_assert(not std::is_invocable_r_v<int*, int()>); static_assert(std::is_invocable_r_v<void, void(int), int>); static_assert(not std::is_invocable_r_v<void, void(int), void>); static_assert(std::is_invocable_r_v<int(*)(), decltype(func2), char>); static_assert(not std::is_invocable_r_v<int(*)(), decltype(func2), void>); }
参见
|
(C++17)
(C++23)
|
以给定参数调用任意
可调用
对象
并可指定返回类型
(C++23 起)
(函数模板) |
|
(C++11)
(C++20 中移除)
(C++17)
|
推导调用可调用对象及参数集的结果类型
(类模板) |
|
(C++11)
|
在未求值语境中获取模板类型参数的引用
(函数模板) |
|
(C++20)
|
规定可调用类型能以给定参数类型集进行调用
(概念) |